Commit f4c6b999 authored by liuyuzhen's avatar liuyuzhen

小程序服务商模式付款

parent e10ff338
......@@ -21,7 +21,7 @@ class PayConst {
const wxSPayMchId = '1517411161';
const wxSPayKey = 'z6o0aQ4Gbceaymj6BKm9PYPjHaUJGokJ';
const wxServiceSslcertPath = '/application/library/Payment/cert/wxservice/1517411161_20181102_cert.pem';
const wxServiceSslkeyPath = '/application/library/Payment/cert/wxservice/1517411161_20181102.pem';
const wxServiceSslkeyPath = '/application/library/Payment/cert/wxservice/1517411161_20181102_key.pem';
const wxPayUrl = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
......
......@@ -131,6 +131,7 @@ class TencentPay {
function createXml($signType='MD5')
{
if($signType=='MD5'){
//echo '加签参数:'.json_encode($this->parameters)."\n";
$this->parameters["sign"] = $this->getSign($this->parameters);//签名
}else{
$this->parameters["sign"] = $this->getHMACSHA1Sign($this->parameters,'sha256');
......@@ -262,8 +263,7 @@ class TencentPay {
$String = $this->formatBizQueryParaMap($Parameters, false);
$String = $String."&key=".$this->key;
\Our\Log::getInstance()->write($this->key,'/data/log/applognew');
//签名步骤三:MD5加密
$String = str_replace(array("\r\n", "\r", "\n"," "), "", $String);
$String = md5($String);
$result_ = strtoupper($String);
return $result_;
......@@ -342,7 +342,6 @@ class TencentPay {
$this->setReturnParameter("return_code","SUCCESS");//设置返回码
}
$returnXml = $this->returnXml();
\Our\Log::getInstance()->write(json_encode($this->data,true),'/data/log/applog');
if($verify) {
return array(
'out_trade_no' => $this->data['out_trade_no'],
......
......@@ -8,6 +8,7 @@ namespace Payment;
*/
class WxLitePay extends \Payment\TencentPay{
private $refundUrl="https://api.mch.weixin.qq.com/secapi/pay/refund";
public function __construct()
{
$this->appid = \Our\PayConst::wxLiteAppId;
......@@ -51,6 +52,76 @@ class WxLitePay extends \Payment\TencentPay{
}
public function refund($param){
if($param['subMchId']){
$this->refundService($param);
}else{
$this->refundCommon($param);
}
}
public function refundService($param){
$this->key = $this->s_key;
$this->sslcert_path = \Our\PayConst::wxServiceSslcertPath;
$this->sslkey_path = \Our\PayConst::wxServiceSslkeyPath;
$total_fee = intval($param['totalFee']);
$refund_fee = intval($param['refundFee']);
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'|| APP_ENV=='lyztest'){
$this->parameters['total_fee'] = 1;
$this->parameters['refund_fee'] = 1;
} else {
$this->parameters['total_fee'] = $total_fee;
$this->parameters['refund_fee'] = $refund_fee;
}
$this->parameters['appid']=$this->s_appid;
$this->parameters['mch_id']=$this->s_mch_id;
$this->parameters['sub_appid']=$this->appid;
$this->parameters['sub_mch_id'] = $param['subMchId'];
$this->parameters['nonce_str'] = $this->createNoncestr(32);
//$this->parameters['transaction_id'] = $param['transactionId'];
$this->parameters['out_trade_no'] = $param['outTradeNo'];
$this->parameters['out_refund_no'] = $param['refundOrderNo'];
$xml = $this->createXml();
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6);
$values = $this->xmlToArray($response);
if ($values['return_code'] != 'SUCCESS') {
return $values;
}
$this->checkSign($values);
return $values;
}
public function refundCommon($param){
$total_fee = intval($param['totalFee']);
$refund_fee = intval($param['refundFee']);
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'){
$this->parameters['total_fee'] = 1;
$this->parameters['refund_fee'] = 1;
} else {
$this->parameters['total_fee'] = $total_fee;
$this->parameters['refund_fee'] = $refund_fee;
}
$this->parameters['out_refund_no'] = $param['refundOrderNo'];
$this->parameters['out_trade_no'] = $param['outTradeNo'];
$this->parameters['op_user_id'] = $this->mch_id;
$this->parameters['nonce_str'] = $this->createNoncestr(32);
$this->parameters['appid'] = \Our\PayConst::wxLiteAppId;
$this->parameters['mch_id'] = \Our\PayConst::wxPayMchId;
$xml = $this->createXml();
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6);
$values = $this->xmlToArray($response);
if ($values['return_code'] != 'SUCCESS') {
return $values;
}
$this->checkSign($values);
return $values;
}
/**
* 类实例
*
......
......@@ -58,18 +58,6 @@ class WxPay extends \Payment\TencentPay
return $wxApiObj;
}
/**
* 作用:产生随机字符串,不长于32位
*/
private function createNoncestr($length = 32)
{
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
public function refund($param){
if($param['subMchId']){
......@@ -80,6 +68,7 @@ class WxPay extends \Payment\TencentPay
}
public function serviceRefund($param){
$this->key = $this->s_key;
$this->sslcert_path = \Our\PayConst::wxServiceSslcertPath;
$this->sslkey_path = \Our\PayConst::wxServiceSslkeyPath;
$total_fee = intval($param['totalFee']);
......@@ -140,73 +129,6 @@ class WxPay extends \Payment\TencentPay
return $values;
}
public function refundWxProgram($param){
if($param['subMchId']){
$this->refundServiceWxProgram($param);
}else{
$this->refundCommonWxProgram($param);
}
}
public function refundServiceWxProgram($param){
$this->sslcert_path = \Our\PayConst::wxServiceSslcertPath;
$this->sslkey_path = \Our\PayConst::wxServiceSslkeyPath;
$total_fee = intval($param['totalFee']);
$refund_fee = intval($param['refundFee']);
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'){
$this->parameters['total_fee'] = 1;
$this->parameters['refund_fee'] = 1;
} else {
$this->parameters['total_fee'] = $total_fee;
$this->parameters['refund_fee'] = $refund_fee;
}
$this->parameters['total_fee'] = $total_fee;
$this->parameters['refund_fee'] =$refund_fee;
$this->parameters['out_refund_no'] = $param['refundOrderNo'];
$this->parameters['out_trade_no'] = $param['outTradeNo'];
$this->parameters['op_user_id'] = $this->mch_id;
$this->parameters['nonce_str'] = $this->createNoncestr(32);
$this->parameters['appid'] = \Our\PayConst::wxSPayAppId;
$this->parameters['mch_id'] = \Our\PayConst::wxSPayMchId;
$this->parameters['sub_appid'] = \Our\PayConst::wxLiteAppId;
$this->parameters['sub_mch_id '] = $param['subMchId'];
$xml = $this->createXml();
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6,true);
$values = $this->xmlToArray($response);
if ($values['return_code'] != 'SUCCESS') {
return $values;
}
$this->checkSign($values);
return $values;
}
public function refundCommonWxProgram($param){
$total_fee = intval($param['totalFee']);
$refund_fee = intval($param['refundFee']);
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'){
$this->parameters['total_fee'] = 1;
$this->parameters['refund_fee'] = 1;
} else {
$this->parameters['total_fee'] = $total_fee;
$this->parameters['refund_fee'] = $refund_fee;
}
$this->parameters['out_refund_no'] = $param['refundOrderNo'];
$this->parameters['out_trade_no'] = $param['outTradeNo'];
$this->parameters['op_user_id'] = $this->mch_id;
$this->parameters['nonce_str'] = $this->createNoncestr(32);
$this->parameters['appid'] = \Our\PayConst::wxLiteAppId;
$this->parameters['mch_id'] = \Our\PayConst::wxPayMchId;
$xml = $this->createXml();
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6);
$values = $this->xmlToArray($response);
if ($values['return_code'] != 'SUCCESS') {
return $values;
}
$this->checkSign($values);
return $values;
}
/**
* 类实例
*
......
......@@ -306,6 +306,7 @@ class OrderServiceModel extends \Business\AbstractModel
$order = $orderDao->findByOrderId($orderId,$orderDao->getOrderDetailField());
//判断订单目前状态是否允许取消
$isAllowCancel = $orderDao->isAllowCancel($order);
$isAllowCance = true;
if ($isAllowCancel) {
$res = $orderDao->updateStatusByOrderId($orderId, ApiConst::orderStateCancel);
if ($res) {
......@@ -331,6 +332,16 @@ class OrderServiceModel extends \Business\AbstractModel
}
public function cancelOne(){
$refundReturnDao = \DAO\Order\RefundReturnModel::getInstance(DbNameConst::masterDBConnectName);
$orderData['storeId']=11;
$orderData['subMchId'] = '1517943841';
$orderData['paySn'] = '280595075137008428';
$orderData['transactionId'] = '4200000191201811099414332980';
$orderData['buyerId'] = 428;
$resultRefund=$refundReturnDao->refundMoney($orderData);
}
//确认收货
public function confirmRecieve($orderId, $memberId)
{
......
......@@ -340,10 +340,11 @@ class RefundReturnModel extends \DAO\AbstractModel {
return false;
}
}else if(intval($orderInfo['paymentType']) == ApiConst::wxProgram){
$wxpay = \Payment\WxPay::getInstance();
$param['subMchId'] = '1517943841';
$refund_return = $wxpay->refundWxProgram($param);
$this->errorMessage= "微信小程序返回:".json_encode($refund_return);
$wxpay = \Payment\WxLitePay::getInstance();
if($orderInfo['subMchId']){
$param['subMchId'] = $orderInfo['subMchId'];
}
$refund_return = $wxpay->refund($param);
if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) {
$this->errorMessage=date('Y-m-d').'微信退款操作执行失败!'.$orderInfo['orderId']."\r\n";
return false;
......
......@@ -41,7 +41,7 @@ class cliOrderCancel extends basecli
protected function autoCancelOrder(){
$orderService=\Business\Order\OrderServiceModel::getInstance(\Our\DbNameConst::masterDBConnectName);
$orderService->cancel(2031);
$orderService->cancelOne();
}
protected function _runCli()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment