Commit e6a862b6 authored by liuyuzhen's avatar liuyuzhen

微信支付服务商相关

parent 353835a8
...@@ -13,9 +13,16 @@ class PayConst { ...@@ -13,9 +13,16 @@ class PayConst {
const wxPayMchId = '1507388351'; const wxPayMchId = '1507388351';
const wxPaySecret = 'appSecret'; const wxPaySecret = 'appSecret';
const wxPayKey = 'kt4gh9FzzlaoPBY074iuF4ZbNmMKc3mS'; const wxPayKey = 'kt4gh9FzzlaoPBY074iuF4ZbNmMKc3mS';
const wxSslcertPath = '/application/library/Payment/cert/wx/apiclient_cert.pem'; const wxSslcertPath = '/application/library/Payment/cert/wx/apiclient_cert.pem';
const wxSslkeyPath = '/application/library/Payment/cert/wx/apiclient_key.pem'; const wxSslkeyPath = '/application/library/Payment/cert/wx/apiclient_key.pem';
//服务商appId和服务商payKey
const wxSPayAppId = 'wxd89203f7621015b7';
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 wxPayUrl = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; const wxPayUrl = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
const qPayAppId = 'qPayAppId'; const qPayAppId = 'qPayAppId';
......
...@@ -29,12 +29,14 @@ class Pay { ...@@ -29,12 +29,14 @@ class Pay {
$orderInfo = $this->getOrder(); $orderInfo = $this->getOrder();
if($data['channel'] == \Our\NameConst::wxAppChannel){ if($data['channel'] == \Our\NameConst::wxAppChannel){
$wxpay = WxPay::getInstance(); $wxpay = WxPay::getInstance();
$orderInfo['subMchId'] = '1517943841';
$return = $wxpay->doPay($orderInfo); $return = $wxpay->doPay($orderInfo);
}else if($data['channel'] == \Our\NameConst::aliApiChannel){ }else if($data['channel'] == \Our\NameConst::aliApiChannel){
$alipay= Alipay::getInstance(); $alipay= Alipay::getInstance();
$return = $alipay->doPay($orderInfo); $return = $alipay->doPay($orderInfo);
}else if($data['channel'] == \Our\NameConst::wxLiteChannel){ }else if($data['channel'] == \Our\NameConst::wxLiteChannel){
$sess = \Yaf\Session::getInstance(); $sess = \Yaf\Session::getInstance();
$orderInfo['subMchId'] = '1517943841';
$authInfo = $sess->get('wxAuthInfo'); $authInfo = $sess->get('wxAuthInfo');
$orderInfo['openid'] = $authInfo['openid']; $orderInfo['openid'] = $authInfo['openid'];
$wxLitePay = WxLitePay::getInstance(); $wxLitePay = WxLitePay::getInstance();
......
...@@ -18,6 +18,9 @@ class TencentPay { ...@@ -18,6 +18,9 @@ class TencentPay {
protected $result =''; protected $result ='';
protected $key = ''; protected $key = '';
protected $mch_id =''; protected $mch_id ='';
protected $s_appid ='';
protected $s_key = '';
protected $s_mch_id ='';
protected $prepay_id =''; protected $prepay_id ='';
protected $tradeType = ''; protected $tradeType = '';
public $data;//接收到的数据,类型为关联数组 public $data;//接收到的数据,类型为关联数组
...@@ -51,6 +54,35 @@ class TencentPay { ...@@ -51,6 +54,35 @@ class TencentPay {
$this->setPrepayId($prepay_id); $this->setPrepayId($prepay_id);
} }
public function setServiceRequestParams($orderInfo){
$this->key = $this->s_key;
$pay_sn = $orderInfo['paySn'];
$total_fee = $orderInfo['orderAmount'];
$this->parameters['appid']=$this->s_appid;
$this->parameters['mch_id']=$this->s_mch_id;
$this->parameters['sub_appid']=$this->s_appid;
$this->parameters['sub_mch_id']=$orderInfo['subMchId'];
$this->parameters['nonce_str']=\Our\CommonExtension::createNoncestr(32);
$this->parameters['body']='订单号:'.implode(',',$orderInfo['orderSns']);
$this->parameters['attach']='r|'.$pay_sn;
$this->parameters['out_trade_no']=$pay_sn;
$this->parameters['fee_type']= \Our\NameConst::currentCNY;
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre'){
$this->parameters['total_fee'] = 1;
}else{
$this->parameters['total_fee'] = $total_fee;
}
if(isset($orderInfo['openid'])&&$orderInfo['openid']){
$this->parameters['openid'] = $orderInfo['openid'];
}
$this->parameters['spbill_create_ip']=\Our\Common::getClientIp();
$this->parameters['notify_url']=$this->notify_url;
$this->parameters['trade_type']= $this->tradeType;
//$this->parameters['openid']=$_SESSION['openid'];
//print_r($this->parameters);exit;
$prepay_id = $this->getPrepayId();
$this->setPrepayId($prepay_id);
}
/** /**
* 作用:设置prepay_id * 作用:设置prepay_id
...@@ -90,6 +122,7 @@ class TencentPay { ...@@ -90,6 +122,7 @@ class TencentPay {
{ {
$xml = $this->createXml(); $xml = $this->createXml();
$this->response = $this->postXmlCurl($xml,$this->pay_url,$this->curl_timeout); $this->response = $this->postXmlCurl($xml,$this->pay_url,$this->curl_timeout);
print_r($this->response);
return $this->response; return $this->response;
} }
......
...@@ -18,11 +18,19 @@ class WxLitePay extends \Payment\TencentPay{ ...@@ -18,11 +18,19 @@ class WxLitePay extends \Payment\TencentPay{
$this->sslkey_path = \Our\PayConst::wxSslkeyPath; $this->sslkey_path = \Our\PayConst::wxSslkeyPath;
$this->pay_url = \Our\PayConst::wxPayUrl; $this->pay_url = \Our\PayConst::wxPayUrl;
$this->tradeType = \Our\PayConst::wxLiteTradeType; $this->tradeType = \Our\PayConst::wxLiteTradeType;
$this->s_mch_id = \Our\PayConst::wxSPayMchId;
$this->s_key = \Our\PayConst::wxSPayKey;
$this->s_appid = \Our\PayConst::wxSPayAppId;
} }
public function doPay($orderInfo){ public function doPay($orderInfo){
$this->setRequestParams($orderInfo); if(isset($orderInfo['subMchId'])){
$this->setServiceRequestParams($orderInfo);
}else{
$this->setRequestParams($orderInfo);
}
//$this->setRequestParams($orderInfo);
$wxAppParameters = $this->getParameters(); $wxAppParameters = $this->getParameters();
$returnData = array( $returnData = array(
'credential'=>array(\Our\NameConst::wxLiteChannel=>$wxAppParameters), 'credential'=>array(\Our\NameConst::wxLiteChannel=>$wxAppParameters),
......
...@@ -22,11 +22,18 @@ class WxPay extends \Payment\TencentPay ...@@ -22,11 +22,18 @@ class WxPay extends \Payment\TencentPay
$this->sslkey_path = \Our\PayConst::wxSslkeyPath; $this->sslkey_path = \Our\PayConst::wxSslkeyPath;
$this->pay_url = \Our\PayConst::wxPayUrl; $this->pay_url = \Our\PayConst::wxPayUrl;
$this->tradeType = \Our\PayConst::wxAppTradeType; $this->tradeType = \Our\PayConst::wxAppTradeType;
$this->s_mch_id = \Our\PayConst::wxSPayMchId;
$this->s_key = \Our\PayConst::wxSPayKey;
$this->s_appid = \Our\PayConst::wxSPayAppId;
} }
public function doPay($orderInfo) public function doPay($orderInfo)
{ {
$this->setRequestParams($orderInfo); if(isset($orderInfo['subMchId'])){
$this->setServiceRequestParams($orderInfo);
}else{
$this->setRequestParams($orderInfo);
}
$wxAppParameters = $this->getParameters(); $wxAppParameters = $this->getParameters();
$returnData = array( $returnData = array(
'credential' => array(\Our\NameConst::wxAppChannel => $wxAppParameters), 'credential' => array(\Our\NameConst::wxAppChannel => $wxAppParameters),
...@@ -64,7 +71,47 @@ class WxPay extends \Payment\TencentPay ...@@ -64,7 +71,47 @@ class WxPay extends \Payment\TencentPay
return $str; return $str;
} }
public function refund($param) public function refund($param){
if($param['subMchId']){
$this->serviceRefund($param);
}else{
$this->commonRefund($param);
}
}
public function serviceRefund($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::wxSPayAppId;
$this->parameters['sub_mch_id '] = $param['subMchId'];
$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 commonRefund($param)
{ {
$total_fee = intval($param['totalFee']); $total_fee = intval($param['totalFee']);
$refund_fee = intval($param['refundFee']); $refund_fee = intval($param['refundFee']);
...@@ -92,8 +139,20 @@ class WxPay extends \Payment\TencentPay ...@@ -92,8 +139,20 @@ class WxPay extends \Payment\TencentPay
$this->checkSign($values); $this->checkSign($values);
return $values; return $values;
} }
public function refundWxProgram($param)
{
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']); $total_fee = intval($param['totalFee']);
$refund_fee = intval($param['refundFee']); $refund_fee = intval($param['refundFee']);
if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'){ if(APP_ENV == 'develop'||APP_ENV == 'test'||APP_ENV == 'pre' || APP_ENV=='ccwdevelop'){
...@@ -103,12 +162,16 @@ class WxPay extends \Payment\TencentPay ...@@ -103,12 +162,16 @@ class WxPay extends \Payment\TencentPay
$this->parameters['total_fee'] = $total_fee; $this->parameters['total_fee'] = $total_fee;
$this->parameters['refund_fee'] = $refund_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_refund_no'] = $param['refundOrderNo'];
$this->parameters['out_trade_no'] = $param['outTradeNo']; $this->parameters['out_trade_no'] = $param['outTradeNo'];
$this->parameters['op_user_id'] = $this->mch_id; $this->parameters['op_user_id'] = $this->mch_id;
$this->parameters['nonce_str'] = $this->createNoncestr(32); $this->parameters['nonce_str'] = $this->createNoncestr(32);
$this->parameters['appid'] = \Our\PayConst::wxLiteAppId; $this->parameters['appid'] = \Our\PayConst::wxLiteAppId;
$this->parameters['mch_id'] = \Our\PayConst::wxPayMchId; $this->parameters['mch_id'] = \Our\PayConst::wxSPayMchId;
$this->parameters['sub_appid'] = \Our\PayConst::wxSPayAppId;
$this->parameters['sub_mch_id '] = $param['subMchId'];
$xml = $this->createXml(); $xml = $this->createXml();
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6); $response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6);
$values = $this->xmlToArray($response); $values = $this->xmlToArray($response);
...@@ -119,6 +182,31 @@ class WxPay extends \Payment\TencentPay ...@@ -119,6 +182,31 @@ class WxPay extends \Payment\TencentPay
return $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;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 class RefundReturnModel extends \DAO\AbstractModel {
} }
}else if(intval($orderInfo['paymentType']) == ApiConst::wxProgram){ }else if(intval($orderInfo['paymentType']) == ApiConst::wxProgram){
$wxpay = \Payment\WxPay::getInstance(); $wxpay = \Payment\WxPay::getInstance();
$refund_return = $wxpay->refund($param); $refund_return = $wxpay->refundWxProgram($param);
$this->errorMessage= "微信小程序返回:".json_encode($refund_return); $this->errorMessage= "微信小程序返回:".json_encode($refund_return);
if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) { if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) {
$this->errorMessage=date('Y-m-d').'微信退款操作执行失败!'.$orderInfo['orderId']."\r\n"; $this->errorMessage=date('Y-m-d').'微信退款操作执行失败!'.$orderInfo['orderId']."\r\n";
......
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