Commit 382c6bbb authored by liuyuzhen's avatar liuyuzhen

小程序支付

parent ba7a12e4
......@@ -21,6 +21,8 @@ class TencentPay {
protected $s_appid ='';
protected $s_key = '';
protected $s_mch_id ='';
protected $s_sslcert_path = 'application/library/Payment/cert/wxservice/1517411161_20181102_cert.pem';
protected $s_sslkey_path = 'application/library/Payment/cert/wxservice/1517411161_20181102_key.pem';
protected $prepay_id ='';
protected $tradeType = '';
public $data;//接收到的数据,类型为关联数组
......@@ -203,8 +205,14 @@ class TencentPay {
/**
* 作用:使用证书,以post方式提交xml到对应的接口url
*/
function postXmlSSLCurl($xml,$url,$second=30)
function postXmlSSLCurl($xml,$url,$second=30,$serviceFlag=false)
{
$certPath = APPLICATION_PATH.$this->sslcert_path;
$keyPath = APPLICATION_PATH.$this->sslkey_path;
if($serviceFlag){
$certPath = APPLICATION_PATH.$this->s_sslcert_path;
$keyPath = APPLICATION_PATH.$this->s_sslkey_path;
}
$ch = curl_init();
//超时时间
curl_setopt($ch,CURLOPT_TIMEOUT,$second);
......@@ -222,10 +230,10 @@ class TencentPay {
//使用证书:cert 与 key 分别属于两个.pem文件
//默认格式为PEM,可以注释
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLCERT, APPLICATION_PATH.$this->sslcert_path);
curl_setopt($ch,CURLOPT_SSLCERT, $certPath);
//默认格式为PEM,可以注释
curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLKEY, APPLICATION_PATH.$this->sslkey_path);
curl_setopt($ch,CURLOPT_SSLKEY, $keyPath);
//post提交方式
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
......
......@@ -168,12 +168,12 @@ class WxPay extends \Payment\TencentPay
$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['appid'] = \Our\PayConst::wxSPayAppId;
$this->parameters['mch_id'] = \Our\PayConst::wxSPayMchId;
$this->parameters['sub_appid'] = \Our\PayConst::wxSPayAppId;
$this->parameters['sub_appid'] = \Our\PayConst::wxLiteAppId;
$this->parameters['sub_mch_id '] = $param['subMchId'];
$xml = $this->createXml();
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6);
$response = $this->postXmlSSLCurl($xml, $this->refundUrl, 6,true);
$values = $this->xmlToArray($response);
if ($values['return_code'] != 'SUCCESS') {
return $values;
......
......@@ -341,6 +341,7 @@ class RefundReturnModel extends \DAO\AbstractModel {
}
}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);
if (!($refund_return['return_code'] == 'SUCCESS' && $refund_return['result_code'] == 'SUCCESS')) {
......
<?php
/**
* User: liuyuzhen
* Date: 2018/11/9
* Time: 11:04
* Description:
*/
define("APPLICATION_PATH", realpath(dirname(__FILE__) . '/../../../')); //指向public的上一级
require APPLICATION_PATH . '/scripts/crontab/baseCli.php';
require APPLICATION_PATH . '/scripts/crontab/common.php';
error_reporting(E_ALL ^ E_NOTICE);
class cliOrderCancel extends basecli
{
const CLI_ADMIN_ID = 255;
private $bDoUnLock = FALSE; // 是否允许释放 LOCK 文件
private $_debug = 0;
private $lockFileName;
private $fromState;
private function mkdirs($dir, $mode = 0777)
{
if (is_dir($dir) || @mkdir($dir, $mode)){
return TRUE;
}
if (!$this->mkdirs(dirname($dir), $mode)){
return FALSE;
}
return @mkdir($dir, $mode);
}
/**
* 析构
*/
public function __destruct()
{
parent::__destruct();
if ($this->bDoUnLock)
{
@unlink($this->lockFileName);
}
}
protected function autoCancelOrder(){
$orderService=\Business\Order\OrderServiceModel::getInstance(\Our\DbNameConst::masterDBConnectName);
$orderService->cancel(2031);
}
protected function _runCli()
{
$this->_debug = isset($this->aArgv[1]) ? intval($this->aArgv[1]) : 0;
if ($this->_debug)
{
echo "*** Debug mode ***\n";
}
// Step: 02 检查是否已有相同CLI在运行中
$lockDir=$this->_getBaseFileName('order');
if(!$this->mkdirs($lockDir)){
echo '****create dir fail ****';
exit;
}
$this->lockFileName = $lockDir .DS.'cancel.locks';
if( file_exists( $this->lockFileName ) )
{
$stat = stat($this->lockFileName);
if( (TIMESTAMP - $stat['mtime']) > 1800 )
{
echo "文件被锁超过1800秒,被强制删除";
@unlink($this->lockFileName);
}
else
{
$this->halt( '[' . date('Y-m-d H:i:s') .'] The CLI is running'."\n");
}
}
$this->bDoUnLock = true;
if(APP_ENV =='pre' || APP_ENV=='product'){
file_put_contents($this->lockFileName ,"running" ); // CLI 独占锁
}
$this->autoCancelOrder();
echo '定单取消成功'."\r\n";
}
}
$oCli = new cliOrderCancel(TRUE);
EXIT;
?>
\ No newline at end of file
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