Authored by whb

Merge branch 'temp'

... ... @@ -81,7 +81,7 @@ class Config
/**
* @var string 日志目录
*/
var $logDir = '/tmp/logs/alibank';
var $logDir = '/Data/logs/pc_pay/alibank';
/**
* @var int 日志等级
... ...
... ... @@ -10,25 +10,25 @@ use WebPlugin\PhpLog;
class Service extends PayAbstract
{
public $config;
public $config;
private $log;
public function __construct(array $paymentParams)
{
$this->logProjectPrefix = 'alibank';
$this->config = new Config();
$myConfig = json_decode($paymentParams["pay_params"]) ;
$this->config->partner = $myConfig->merchant_id;
$this->config->alipay_key = $myConfig->merchant_key;
$this->config->sellerMail = $myConfig->merchant_other_code;
public function __construct(array $paymentParams)
{
$this->logProjectPrefix = 'alibank';
$this->config = new Config();
$myConfig = json_decode($paymentParams["pay_params"]);
$this->config->partner = $myConfig->merchant_id;
$this->config->alipay_key = $myConfig->merchant_key;
$this->config->sellerMail = $myConfig->merchant_other_code;
$this->log = new PhpLog($this->config->logDir, "PRC", $this->config->logLevel);
}
/**
* 获取时间戳
*/
private function getTimestamp()
}
/**
* 获取时间戳
*/
private function getTimestamp()
{
$url = "https://mapi.alipay.com/gateway.do?service=query_timestamp&partner=" . trim(strtolower($this->config->partner)) . "&_input_charset=" . trim(strtolower($this->config->input_charset));
... ... @@ -38,173 +38,178 @@ class Service extends PayAbstract
$encrypt_key = $itemEncrypt_key->item(0)->nodeValue;
return $encrypt_key;
}
public function getPayRequestPars(Reqparams $params)
{
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
$loseTime = intval(($params->orderTime + 7200 -time())/60);
// $loseTime = intval((strtotime(date("Y-m-d 10:00:00", strtotime("+1 day")))-time())/60);
$parameter = array(
'service' => $this->config->service,
'partner' => $this->config->partner,
'_input_charset' => $this->config->input_charset,
'notify_url' => $baseUrl . $this->config->notify_url,
'return_url' => $baseUrl . $this->config->return_url,
/* 业务参数 */
'subject' => $params->goodsName,
'out_trade_no' => $params->orderCode.'_'.$params->paymentParameter,
'total_fee' => $params->totalFee / 100, //单位为元
'payment_type' => $this->config->payment_type,
'defaultbank' => $params->paymentParameter,
'seller_email' => $this->config->sellerMail,
}
public function getPayRequestPars(Reqparams $params)
{
$baseUrl = $this->getBaseNoticeUrl($params->isTest);
$loseTime = intval(($params->orderTime + 7200 - time()) / 60);
// $loseTime = intval((strtotime(date("Y-m-d 10:00:00", strtotime("+1 day")))-time())/60);
$parameter = array(
'service' => $this->config->service,
'partner' => $this->config->partner,
'_input_charset' => $this->config->input_charset,
'notify_url' => $baseUrl . $this->config->notify_url,
'return_url' => $baseUrl . $this->config->return_url,
/* 业务参数 */
'subject' => $params->goodsName,
'out_trade_no' => $params->orderCode . '_' . $params->paymentParameter,
'total_fee' => $params->totalFee / 100, //单位为元
'payment_type' => $this->config->payment_type,
'defaultbank' => $params->paymentParameter,
'seller_email' => $this->config->sellerMail,
// 'it_b_pay' => $loseTime . 'm'
);
if($this->config->anti_fishing['timestamp_enable']) {
$anti_phishing_key = $this->getTimestamp();
if(!empty($anti_phishing_key)) {
$parameter['anti_phishing_key'] = $anti_phishing_key;
}
}
if($this->config->anti_fishing['ip_enable']) {
$parameter['exter_invoke_ip'] = $params->spbill_create_ip;
}
);
if ($this->config->anti_fishing['timestamp_enable']) {
$anti_phishing_key = $this->getTimestamp();
if (!empty($anti_phishing_key)) {
$parameter['anti_phishing_key'] = $anti_phishing_key;
}
}
if ($this->config->anti_fishing['ip_enable']) {
$parameter['exter_invoke_ip'] = $params->spbill_create_ip;
}
// 除去数组中的空值和签名参数
$para_filter = array();
foreach ($parameter AS $k => $v) {
if($k == "sign" || $k == "sign_type" || $v == "") {
if ($k == "sign" || $k == "sign_type" || $v == "") {
continue;
} else {
$para_filter[$k] = $parameter[$k];
}
}
ksort($para_filter);
reset($para_filter);
$param = '';
$sign = '';
foreach ($para_filter AS $key => $val) {
$param .= "$key=" .urlencode($val). "&";
$sign .= "$key=$val&";
}
$param = substr($param, 0, -1);
$sign = substr($sign, 0, -1);
ksort($para_filter);
reset($para_filter);
$param = '';
$sign = '';
foreach ($para_filter AS $key => $val) {
$param .= "$key=" . urlencode($val) . "&";
$sign .= "$key=$val&";
}
$param = substr($param, 0, -1);
$sign = substr($sign, 0, -1);
//如果存在转义字符,那么去掉转义
if(get_magic_quotes_gpc()){$sign = stripslashes($sign);}
if (get_magic_quotes_gpc()) {
$sign = stripslashes($sign);
}
$sign .= $this->config->alipay_key;
$result = array(
$result = array(
'pay_url' => $this->config->pay_url,
'pars' => $param . "&sign=" . md5($sign). "&sign_type=" . $this->config-> sign_type,
'pars' => $param . "&sign=" . md5($sign) . "&sign_type=" . $this->config->sign_type,
'reqType' => 'get'
);
return $result;
}
public function parseResponse(array $arrResponse)
{
/* 返回示例
* http://www.yohobuy.com/pay/notice/alipayreturn?buyer_email=tds%40smartunite.com&buyer_id=2088302294447308&exterface=create_direct_pay_by_user&is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3I7xtEV5W65QRToFQ5fPrXsVxt12e%252FExCtC1XNiKnuRwupLaVLAR&notify_time=2011-06-11+07%3A48%3A10&notify_type=trade_status_sync&out_trade_no=1061003000&payment_type=1&seller_email=shop%40yoho.cn&seller_id=2088001550230585&subject=YOHO%E5%95%86%E5%93%81&total_fee=0.01&trade_no=2011061199833830&trade_status=TRADE_SUCCESS&sign=ca1c49f58d17eaa57aac308d0ac64434&sign_type=MD5
*/
);
return $result;
}
public function parseResponse(array $arrResponse)
{
/* 返回示例
* http://www.yohobuy.com/pay/notice/alipayreturn?buyer_email=tds%40smartunite.com&buyer_id=2088302294447308&exterface=create_direct_pay_by_user&is_success=T&notify_id=RqPnCoPT3K9%252Fvwbh3I7xtEV5W65QRToFQ5fPrXsVxt12e%252FExCtC1XNiKnuRwupLaVLAR&notify_time=2011-06-11+07%3A48%3A10&notify_type=trade_status_sync&out_trade_no=1061003000&payment_type=1&seller_email=shop%40yoho.cn&seller_id=2088001550230585&subject=YOHO%E5%95%86%E5%93%81&total_fee=0.01&trade_no=2011061199833830&trade_status=TRADE_SUCCESS&sign=ca1c49f58d17eaa57aac308d0ac64434&sign_type=MD5
*/
$this->log->LogInfo("===开始解析支付宝银行的回调参数===");
$this->log->logInfo("-----回调参数为---");
$this->log->logInfo(var_export($arrResponse), true);
if(isset($arrResponse['q'])){
unset($arrResponse['q']);
}
$rsp = new Rspparams();
if(!$this->checkResponse($arrResponse))
{
$this->log->LogInfo("验证支付宝银行的回调参数失败");
//验证不成功
$rsp->payResult = -1;
}
else
{
$rsp->bankName = "";
$outTradeNo = $arrResponse["out_trade_no"];
if (isset($arrResponse['q'])) {
unset($arrResponse['q']);
}
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
$this->log->LogInfo("---验证支付宝银行的回调参数失败---");
//验证不成功
$rsp->payResult = -1;
} else {
$this->log->LogInfo("---验证支付宝银行的回调参数成功---");
$rsp->bankName = "";
$outTradeNo = $arrResponse["out_trade_no"];
// if(strlen($outTradeNo) > 9) {
// $outTradeNo = substr($outTradeNo, 2);
// }
//支付订单处理
$orderCodeArr = explode('_',$outTradeNo);
if(count($orderCodeArr) == 2){
$rsp->orderCode = $orderCodeArr[0];
$rsp->bankName = $orderCodeArr[1];
}else{
$rsp->orderCode = $outTradeNo;
$rsp->bankName = "";
}
$rsp->payResult = $this->convertResult($arrResponse["trade_status"]);
$rsp->payTime = isset($arrResponse["gmt_payment"]) ? $arrResponse["gmt_payment"] : time();
$rsp->totalFee = $arrResponse["total_fee"];
$rsp->resultMsg = $arrResponse["notify_type"];
//添加支付订单号和交易号和银行的流水号
$rsp->payOrderCode = $outTradeNo;
$rsp->tradeNo = $arrResponse['trade_no'];
$rsp->bankBillNo = $arrResponse['bank_seq_no'] ? $arrResponse['bank_seq_no'] : "";
}
return $rsp;
}
protected function convertResult($resultCode)
{
if($resultCode == "TRADE_SUCCESS")
{
return 200;
}
return 400;
}
/**
* 除去数组中的空值和签名参数
* @param $para 签名参数组
* return 去掉空值与签名参数后的新签名参数组
*/
private function paraFilter($para) {
$para_filter = array();
foreach ($para as $key=>$val) {
if($key == "sign" || $key == "sign_type" || $val == "")continue;
else $para_filter[$key] = $para[$key];
}
return $para_filter;
}
/**
* 对数组排序
* @param $para 排序前的数组
* return 排序后的数组
*/
private function argSort($para) {
ksort($para);
reset($para);
return $para;
}
/**
* 验证回复的正确性
* @see QPay_Utils_Abstract::verifResponse()
*/
protected function checkResponse(array $arrResponse)
{
ksort($arrResponse);
reset($arrResponse);
$sign = '';
foreach ($arrResponse AS $key=>$val)
{
if ($key != 'sign' && $key != 'sign_type' && $key != 'code')
{
$sign .= "$key=$val&";
}
}
$sign = substr($sign, 0, -1) . $this->config->alipay_key;
return md5($sign) != $arrResponse['sign'] ? false : true;
}
//支付订单处理
$orderCodeArr = explode('_', $outTradeNo);
if (count($orderCodeArr) == 2) {
$rsp->orderCode = $orderCodeArr[0];
$rsp->bankName = $orderCodeArr[1];
} else {
$rsp->orderCode = $outTradeNo;
$rsp->bankName = "";
}
$rsp->payResult = $this->convertResult($arrResponse["trade_status"]);
$rsp->payTime = isset($arrResponse["gmt_payment"]) ? $arrResponse["gmt_payment"] : time();
$rsp->totalFee = $arrResponse["total_fee"];
$rsp->resultMsg = $arrResponse["notify_type"];
//添加支付订单号和交易号和银行的流水号
$rsp->payOrderCode = $outTradeNo;
$rsp->tradeNo = $arrResponse['trade_no'];
$rsp->bankBillNo = $arrResponse['bank_seq_no'] ? $arrResponse['bank_seq_no'] : "";
$this->log->LogInfo('----支付宝银行回调处理结果为----');
$this->log->LogInfo(var_export($rsp, true));
}
return $rsp;
}
protected function convertResult($resultCode)
{
if ($resultCode == "TRADE_SUCCESS") {
return 200;
}
return 400;
}
/**
* 除去数组中的空值和签名参数
* @param $para 签名参数组
* return 去掉空值与签名参数后的新签名参数组
*/
private function paraFilter($para)
{
$para_filter = array();
foreach ($para as $key => $val) {
if ($key == "sign" || $key == "sign_type" || $val == "") continue;
else $para_filter[$key] = $para[$key];
}
return $para_filter;
}
/**
* 对数组排序
* @param $para 排序前的数组
* return 排序后的数组
*/
private function argSort($para)
{
ksort($para);
reset($para);
return $para;
}
/**
* 验证回复的正确性
* @see QPay_Utils_Abstract::verifResponse()
*/
protected function checkResponse(array $arrResponse)
{
ksort($arrResponse);
reset($arrResponse);
$sign = '';
foreach ($arrResponse AS $key => $val) {
if ($key != 'sign' && $key != 'sign_type' && $key != 'code') {
$sign .= "$key=$val&";
}
}
$sign = substr($sign, 0, -1) . $this->config->alipay_key;
return md5($sign) != $arrResponse['sign'] ? false : true;
}
}
\ No newline at end of file
... ...
<?php
namespace WebPlugin\Pay\Alimobilemini;
/**
* 手机支付配置文件
* @author tongds
*
*/
class Config
{
var $partner = '2088701661478015';
/**
* @var string 日志目录
*/
var $logDir = '/Data/logs/pc_pay/alimobilemini';
/**
* @var string 日志等级
*/
var $logLevel = 2; // 记录信息日志
}
... ...
<?php
namespace WebPlugin\Pay\Alimobilemini;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
/**
* 手机支付返回
* @author tongds
*
*/
class Service extends PayAbstract
{
public $config;
private $log;
private $utils;
public function __construct(array $paymentParams)
{
$this->logProjectPrefix = 'alimobilemini';
$this->utils = new Utils();
$this->config = new Config();
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
/**
* 处理支付宝极简支付的结果
*
* @param array $arrResponse
* @return Rspparams
*/
public function parseResponse(array $arrResponse)
{
$rsp = new Rspparams();
// ksort($arrResponse);
// ##组织代签名字符串#################
// $sign=$arrResponse['sign'];
// foreach($arrResponse as $a =>$v)
// {
// if(in_array($a,array('sign','sign_type')) || $v=="") continue;
// $data[]=$a.'='.$v;
// }
// $datastr=implode("&", $data);
// ##################################
$isVerify = $this->utils->getSignVeryfy($arrResponse);
if ($isVerify) {
//验证成功
$rsp->bankName = "";
$rsp->orderCode = $arrResponse['out_trade_no'];
$rsp->payResult = $this->convertResult($arrResponse['trade_status']);
$rsp->payTime = $arrResponse["gmt_create"];
$rsp->totalFee = $arrResponse["total_fee"];
$rsp->resultMsg = $arrResponse["trade_no"];
//添加支付订单号和交易号
$rsp->payOrderCode = $arrResponse['out_trade_no'];
$rsp->tradeNo = $arrResponse['trade_no'];
$rsp->bankBillNo = "";
$this->log->logInfo(var_export($arrResponse, true));
$this->log->logInfo('======alimobilemini成功===');
} else {
//不成功
$rsp->payResult = -1;
$this->log->logInfo(var_export($arrResponse, true));
$this->log->logInfo('======alimobilemini失败===订单号----->' . $arrResponse['out_trade_no']);
}
return $rsp;
}
/**
* 转换结果
*
* @param string $resultCode 返回码
* @return int
*/
protected function convertResult($resultCode)
{
if ($resultCode == "TRADE_SUCCESS" || $resultCode == "TRADE_FINISHED") {
return 200;
}
return -1;
}
}
\ No newline at end of file
... ...
<?php
namespace WebPlugin\Pay\Alimobilemini;
use WebPlugin\Pay\PayAbstract;
/**
* 支付宝手机极简支付工具类
* @author Smile
*
*/
class Utils extends PayAbstract
{
/**
* 构造函数
*/
public function __construct()
{
}
/**RSA签名
* $data待签名数据
* 签名用商户私钥,必须是没有经过pkcs8转换的私钥
* 最后的签名,需要用base64编码
* return Sign签名
*/
function sign($data)
{
//转换为openssl密钥,必须是没有经过pkcs8转换的私钥
$res = openssl_get_privatekey($this->priKey);
//调用openssl内置签名方法,生成签名$sign
openssl_sign($data, $sign, $res);
//释放资源
openssl_free_key($res);
//base64编码
$sign = base64_encode($sign);
return $sign;
}
/**
* RSA验签
* 验签用支付宝公钥
*
* return 验签是否通过 bool值
* @param array $data 待签名数据
* @param string $sign 需要验签的签名
* @return bool 验签是否通过 bool值
*/
function verify($data, $sign)
{
$pubKeyPath = dirname(__FILE__) . '/key/alipay_public_key.pem';
//转换为openssl格式密钥
$pubKey = file_get_contents($pubKeyPath);
$res = openssl_get_publickey($pubKey);
if ($res == false) {
while ($text = openssl_error_string())
echo "$text \n";
}
//调用openssl内置方法验签,返回bool值
$result = (bool)openssl_verify($data, base64_decode($sign), $res);
//释放资源
openssl_free_key($res);
//返回资源是否成功
return $result;
}
/**
* 获取返回时的签名验证结果
*
* @param $para_temp 通知返回来的参数数组
* @return string $sign 返回的签名结果
*/
function getSignVeryfy($para_temp)
{
//支付宝公钥路径
$pubKeyPath = dirname(__FILE__) . '/key/alipay_public_key.pem';
//签名类型:RSA
$sign_type = $para_temp['sign_type'];
//签名
$sign = $para_temp['sign'];
//除去待签名参数数组中的空值和签名参数
$para_filter = self::paraFilter($para_temp);
//对待签名参数数组排序
$para_sort = self::argSort($para_filter);
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr = self::createLinkstring($para_sort);
switch (strtoupper($sign_type)) {
case "RSA" :
$isSgin = self::rsaVerify($prestr, $pubKeyPath, $sign);
break;
default :
$isSgin = false;
}
return $isSgin;
}
/**
* 除去数组中的空值和签名参数
* @param array $para 签名参数组
* @return array 去掉空值与签名参数后的新签名参数组
*/
function paraFilter($para)
{
$para_filter = array();
while (list ($key, $val) = each($para)) {
if ($key == "sign" || $key == "sign_type" || $val == "") {
continue;
} else {
$para_filter[$key] = $para[$key];
}
}
return $para_filter;
}
/**
* 对数组排序
* @param array $para 排序前的数组
* @return array 排序后的数组
*/
function argSort($para)
{
ksort($para);
reset($para);
return $para;
}
/**
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
* @param array $para 需要拼接的数组
* @return string 拼接完成以后的字符串
*/
function createLinkstring($para)
{
$arg = "";
while (list ($key, $val) = each($para)) {
$arg .= $key . "=" . $val . "&";
}
//去掉最后一个&字符
$arg = substr($arg, 0, count($arg) - 2);
//如果存在转义字符,那么去掉转义
if (get_magic_quotes_gpc()) {
$arg = stripslashes($arg);
}
return $arg;
}
/**
* RSA验签
* @param array $data 待签名数据
* @param string $ali_public_key_path 支付宝的公钥文件路径
* @param string $sign 要校对的的签名结果
* @return bool 验证结果
*/
function rsaVerify($data, $ali_public_key_path, $sign)
{
$pubKey = file_get_contents($ali_public_key_path);
$res = openssl_get_publickey($pubKey);
$result = (bool)openssl_verify($data, base64_decode($sign), $res);
openssl_free_key($res);
return $result;
}
}
\ No newline at end of file
... ...
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRAFljhNhgPdyPu
BV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQEB/VsW8OoM8fxn67UDYuyBTqA
23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5KsiNG9zpgmLCUYuLkxpLQIDAQAB
-----END PUBLIC KEY-----
... ...
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDNtQee4Q7qVyjIkrLfIKcOajn4IGQyALkSclFdCrYcZ3WhFWdH
+cjt/CGW8KuxX4CJWZO0LECA9avJFsipqZ339jz4nWma5yMoLpEFu55J2sJE3Mv1
USe+3/egRfOmHGWa3GHAPjglyux10ZStLkUoMSrNZxSeDKnaAaYLYxmB+wIDAQAB
AoGAdqF3Ap5iPq0DPSC0/U7UaNDEG596iQe3s7avy4uY2KqlwL8aL/0SboTgTi7/
pSwhcZRyRQ7cKEMFzdNQ59+E1Gm1XqbZIKAb8D16JtcVrPBdKBCb5DOizW/6nKUk
djo2FjuSB6nZCy5pZoyxjHkvOKZ0I+YfjYiNZGCCcRnYQmkCQQDqI7VsiywgqXUC
anKzo/U8+exVofhe8Lrcd9pPeolaA9L9amCpW7VOBSlwnSuD7xX77/9XLUo3Ry1n
PewANsQ/AkEA4Om+p5ZjR32v4nJkuE5LEMtDIei1Hhz4tdsBq/xIfY/wNy5Z8Kmo
vpn0D1xF4qN99E7pp7SjRx/lW6VSn/4jRQJBAMXEO63fL/q2p7rOpuvNhYtnnpQG
J4Ap3evy4FdZrUJ3EHQ0skjayZ2JBqO0XdkmzW7sHMVJ3/IpENSvnPPhTokCQBw5
ONOO66Zs/0VLVZhLOuBAoYv/x7qfqBYqBWuvnOkkxuAl0OOCZsqERzwmOB7YpVWj
EW8aG+Mw/Xcip9ur6IECQDLwM0wvlCGyQaOClhlzlWPq0pgEpnnJMwkfyXbx03Cb
DyXYdx6FDfqcCKlHcfHevuCVczR4aT4/rUClJB39AqU=
-----END RSA PRIVATE KEY-----
... ...
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDNtQee4Q7qVyjIkrLfIKcOajn4
IGQyALkSclFdCrYcZ3WhFWdH+cjt/CGW8KuxX4CJWZO0LECA9avJFsipqZ339jz4
nWma5yMoLpEFu55J2sJE3Mv1USe+3/egRfOmHGWa3GHAPjglyux10ZStLkUoMSrN
ZxSeDKnaAaYLYxmB+wIDAQAB
-----END PUBLIC KEY-----
... ...
... ... @@ -84,7 +84,7 @@ class Config
/**
* @var string 日志目录
*/
var $logDir = '/tmp/logs/alibank';
var $logDir = '/Data/logs/pc_pay/alipay';
/**
* @var string 日志等级
... ...
... ... @@ -100,6 +100,10 @@ class Service extends PayAbstract
'pars' => $param . "&sign=" . md5($sign) . "&sign_type=" . $this->config->sign_type,
'reqType' => 'get'
);
$this->log->LogInfo('----支付宝回调处理结果为----');
$this->log->LogInfo(var_export($result, true));
return $result;
}
... ... @@ -117,9 +121,11 @@ class Service extends PayAbstract
}
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
$this->log->logInfo("-----支付宝回调参数验证签名失败---");
//验证不成功
$rsp->payResult = -1;
} else {
$this->log->logInfo("-----支付宝回调参数验证签名成功---");
$rsp->bankName = "";
$outTradeNo = $arrResponse["out_trade_no"];
$rsp->orderCode = $outTradeNo;
... ...
... ... @@ -5,10 +5,12 @@ namespace WebPlugin\Pay\Allinpay;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
class Service extends PayAbstract
{
var $config;
public $config;
private $log;
public function __construct(array $paymentParams)
{
... ... @@ -17,6 +19,8 @@ class Service extends PayAbstract
$myConfig = json_decode($paymentParams["pay_params"]);
$this->config->merchantId = $myConfig->merchant_id;
$this->config->merchantKey = $myConfig->merchant_key;
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
/**
... ... @@ -63,10 +67,18 @@ class Service extends PayAbstract
*/
public function parseResponse(array $arrResponse)
{
$this->log->LogInfo("===开始处理通联支付的回调参数===");
$this->log->logInfo("-----回调参数为---");
$this->log->logInfo(var_export($arrResponse, true));
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
$this->log->logInfo("-----验证通联支付回调参数失败---");
$rsp->payResult = -1;
} else {
$this->log->logInfo("-----验证通联支付回调参数成功---");
$rsp->bankName = "";
$rsp->orderCode = $arrResponse["orderNo"];
$rsp->payResult = $this->convertResult($arrResponse["payResult"]);
... ...
... ... @@ -112,7 +112,7 @@ class Config
/**
* @var string 日志目录
*/
var $logDir = '/tmp/logs/shengpay';
var $logDir = '/Data/logs/pc_pay/shengpay';
/**
* @var string 日志等级
... ...
... ... @@ -108,15 +108,19 @@ class Service extends PayAbstract
*/
function parseResponse(Array $arrResponse)
{
$this->log->LogInfo("===开始处理盛付通的请求参数===");
$this->log->logInfo("-----请求参数为---");
$this->log->LogInfo("===开始处理盛付通的回调参数===");
$this->log->logInfo("-----回调参数为---");
$this->log->logInfo(var_export($arrResponse, true));
$rsp = new Rspparams();
if (!$this->checkResponse($arrResponse)) {
$this->log->logInfo("-----验证盛付通回调参数失败---");
//验证不成功
$rsp->payResult = -1;
} else {
$this->log->logInfo("-----验证盛付通回调参数成功---");
$rsp->bankName = "";
$rsp->orderCode = $arrResponse["OrderNo"];
$rsp->payResult = $this->convertResult($arrResponse["Status"]);
... ...
... ... @@ -58,7 +58,7 @@ class Config
/**
* @var string 日志目录
*/
var $logDir = '/tmp/logs/tenpay';
var $logDir = '/Data/logs/pc_pay/tenpay';
/**
* @var string 日志等级
... ...
... ... @@ -35,20 +35,22 @@ class Service extends PayAbstract
*/
public function parseResponse(array $package)
{
$this->log->logInfo("===开始解析银联支付的回调参数===");
$this->log->logInfo("===回调参数为===");
$this->log->LogInfo(var_export($package, true));
$verify = false;
$responseData = new Rspparams();
if (!isset($package['respCode']) || $package['respCode'] !== '00') {
$this->log->LogInfo('支付返回码有误');
$this->log->LogInfo('银联支付返回码有误');
$responseData->payResult = -1;
return $responseData;
}
if (isset($package['signature'])) { // TODO isset($package['signature']) && verify($package)验证签名待做
$verify = true;
$this->log->LogInfo('验签成功');
$this->log->LogInfo('银联支付验签成功');
}
if ($verify) {
... ... @@ -67,6 +69,7 @@ class Service extends PayAbstract
$responseData->payResult = -1;
}
$this->log->logInfo("===银联支付的回调参数处理结果为===");
$this->log->LogInfo(var_export($responseData, true));
return $responseData;
... ...
... ... @@ -53,10 +53,10 @@ const SDK_FRONT_NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/unionpaywebretur
const SDK_BACK_NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/unionpaywebnotice';
//文件下载目录
const SDK_FILE_DOWN_PATH = '/tmp/unionpay/files/';
const SDK_FILE_DOWN_PATH = '/Data/logs/pc_pay/unionpay/files/';
//日志 目录
const SDK_LOG_FILE_PATH = '/tmp/logs/unionpay/';
const SDK_LOG_FILE_PATH = '/Data/logs/pc_pay/unionpay/';
//日志级别
const SDK_LOG_LEVEL = 2; // 记录信息日志
... ...
... ... @@ -49,10 +49,10 @@ const SDK_FRONT_NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/unionpaywebretur
const SDK_BACK_NOTIFY_URL = 'http://www.yohobuy.com/pay/notice/unionpaywebnotice';
//文件下载目录
const SDK_FILE_DOWN_PATH = '/tmp/unionpay/files/';
const SDK_FILE_DOWN_PATH = '/Data/logs/pc_pay/unionpay/files/';
//日志 目录
const SDK_LOG_FILE_PATH = '/tmp/logs/unionpay/';
const SDK_LOG_FILE_PATH = '/Data/logs/pc_pay/unionpay/';
//日志级别
const SDK_LOG_LEVEL = 2;
... ...
... ... @@ -19,7 +19,7 @@ class Config
/**
* @var string 日志目录
*/
var $logDir = '/tmp/logs/wechatqrcode';
var $logDir = '/Data/logs/pc_pay/wechatqrcode';
/**
* @var string 日志等级
... ...
... ... @@ -21,10 +21,11 @@ class Service extends PayAbstract
private $payCurl;
private $log;
public function __construct(array $paymentParams) {
public function __construct(array $paymentParams)
{
$this->logProjectPrefix = 'wechatpay';
$this->config = new Config();
$environParam = 'pay_'.APPLICATION_ENV.'_url';
$environParam = 'pay_' . APPLICATION_ENV . '_url';
$this->payCurl = $this->config->$environParam;
$this->appKey = $this->config->app_key;
$this->privateKey = $this->config->private_key;
... ... @@ -33,7 +34,8 @@ class Service extends PayAbstract
$this->log = new PhpLog($this->config->logDir, 'PRC', $this->config->logLevel);
}
public function getPayRequestPars(Reqparams $params) {
public function getPayRequestPars(Reqparams $params)
{
$this->orderCode = $params->orderCode;
$result = array(
'pay_url' => $this->config->payment_url,
... ... @@ -49,7 +51,8 @@ class Service extends PayAbstract
* @return string
* @internal param array $orderCode
*/
public function pay(array $orderInfo) {
public function pay(array $orderInfo)
{
$this->log->LogInfo("===开始处理微信扫码支付的请求参数===");
$this->log->logInfo("-----请求参数为---");
$this->log->logInfo(var_export($orderInfo, true));
... ... @@ -74,7 +77,7 @@ class Service extends PayAbstract
);
$pars = '';
foreach ($parameter as $p_key => $p_val) {
$pars.=$p_key . '=' . urlencode($p_val) . '&';
$pars .= $p_key . '=' . urlencode($p_val) . '&';
}
$payUrlInfo = array(
'pay_url' => $this->payCurl,
... ... @@ -90,7 +93,8 @@ class Service extends PayAbstract
return array('pay_url' => $payUrl);
}
public function parseResponse(array $data) {
public function parseResponse(array $data)
{
/* 返回示例
* http://www.yohobuy.com/pay/notice/wechatqrcodereturn?ordercode=93465435
*/
... ... @@ -108,7 +112,7 @@ class Service extends PayAbstract
$rsp = new Rspparams();
// 支付成功
if(isset($result['trade_state']) && $result['trade_state'] === 'SUCCESS'){
if (isset($result['trade_state']) && $result['trade_state'] === 'SUCCESS') {
$rsp->payResult = 200;
$rsp->bankName = "WX";
$rsp->orderCode = $data['orderCode'];
... ... @@ -119,7 +123,8 @@ class Service extends PayAbstract
$rsp->payOrderCode = $data["orderCode"];
$rsp->tradeNo = $result["out_trade_no"];
$rsp->bankBillNo = $result['bank_type'];
}else{
} else {
$this->log->logInfo("===微信扫码支付失败===");
$rsp->payResult = -1;
}
... ...
... ... @@ -14,6 +14,7 @@ use WebPlugin\Pay\weixin\lib\WxPayConfig;
use WebPlugin\Pay\weixin\lib\WxPayNativePay;
use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder;
use WebPlugin\PhpLog;
/**
* 支付有关方法
... ... @@ -25,6 +26,22 @@ use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder;
*/
class PayModel
{
// 日志等级,2表示记录信息等级的日志
const LOG_LEVEL = 2;
// 支付方式有关接口调用日志
const PAYMENT_LIST_LOG = '/Data/logs/pc_pay/payment_list';
// 向ERP提交订单状态有关接口调用日志和更新订单状态有关接口调用日志
const ORDER_STATUS_LOG = '/Data/logs/pc_pay/order_status';
// 获取或者更新订单支付银行的接口调用日志
const ORDER_BANK_LOG = '/Data/logs/pc_pay/order_bank';
// 根据用户UID获取订单数有关接口调用日志
const ORDER_COUNT_LOG = '/Data/logs/pc_pay/order_count';
// 发送短信有关接口调用日志
const SEND_MESSAGE_LOG = '/Data/logs/pc_pay/send_message';
// 是否老用户订单数判断值
const OLD_USER_LIMIT = 1;
/**
* 获取支付方式选择页面有关信息
*
... ... @@ -94,8 +111,14 @@ class PayModel
// 用户ID
$result['uid'] = $uid;
// 初始化日志
$log = new PhpLog(self::PAYMENT_LIST_LOG, 'PRC', self::LOG_LEVEL);
// 获取支付途径列表
$log->LogInfo('===开始调用支付方式列表接口,接口方法为web.SpaceOrders.getPaymentList===');
$payTypes = PayData::getPaymentList();
$log->LogInfo('===结束调用支付方式列表接口,返回结果为===');
$log->LogInfo(var_export($payTypes, true));
$defaultPayType = 0;
$types = array();
if (isset($payTypes['data']) && !empty($payTypes['data'])) {
... ... @@ -125,16 +148,37 @@ class PayModel
// 无需付款
if (isset($order["payment_amount"]) && $order["payment_amount"] == 0) {
// 初始化日志
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===[' . $orderCode . ']===');
// ERP提交订单状态
PayData::submitOrderStatus($orderCode, 0, '', '', 0, '', '', '');
$log->LogInfo('===开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');
$log->LogInfo('===请求参数为orderCode=' . $orderCode . '===');
$erpReturn = PayData::submitOrderStatus($orderCode, 0, '', '', 0, '', '', '');
$log->LogInfo('===结束调用ERP提交订单状态接口,返回结果为===');
$log->LogInfo(var_export($erpReturn, true));
// 更新订单的状态
PayData::updateOrderStatus($order['order_id'], $uid, 0, 'Y', '');
$log->LogInfo('===开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');
$log->LogInfo('===请求参数为orderId=' . $order['order_id'] . 'uid=' . $uid . '===');
$updateOrderStatus = PayData::updateOrderStatus($order['order_id'], $uid, 0, 'Y', '');
$log->LogInfo('===结束调用更新订单状态接口,返回结果为===');
$log->LogInfo(var_export($updateOrderStatus, true));
$result['notNeedPay'] = true;
break;
}
// 记录支付方式
// 初始化日志
$log = new PhpLog(self::ORDER_BANK_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===开始调用记录支付方式接口,接口方法为web.SpaceOrders.getOrderPayBank===');
$log->LogInfo('===请求参数为orderCode=' . $orderCode . '===');
$bankRecord = PayData::getBankByOrder($orderCode);
$log->LogInfo('===结束调用记录支付方式接口,返回结果为===');
$log->LogInfo(var_export($bankRecord, true));
if (isset($bankRecord['data']['bankCode']) && !empty($bankRecord['data']['bankCode'])) {
$payRecord = $bankRecord['data']['bankCode'];
} else {
... ... @@ -158,11 +202,17 @@ class PayModel
// 是否是老用户(用于订单统计)
$orderCount = 0;
// 初始化日志
$log = new PhpLog(self::ORDER_COUNT_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===开始调用查询用户订单数接口,接口方法为web.SpaceOrders.getOrderCountByUid===');
$orders = PayData::getOrderCountByUid($uid);
$log->LogInfo('===结束调用查询用户订单数接口,返回结果为===');
$log->LogInfo(var_export($orders, true));
if (isset($orders['data']) && !empty($orders['data'])) {
$orderCount = $orders['data']['total'];
}
$result['isOldUser'] = (intval($orderCount) > 1) ? true : false;
$result['isOldUser'] = (intval($orderCount) > self::OLD_USER_LIMIT) ? true : false;
// 订单数(用于订单统计)
$result['orderCount'] = $orderCount;
$result['is_advance'] = $order['attribute'] == 5 ? 'Y' : 'N';
... ... @@ -424,6 +474,11 @@ class PayModel
break;
}
// 初始化日志
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('========[' . $orderCode . ']========');
$log->LogInfo('========开始查询微信扫码支付状态========');
// 组装微信支付的订单号
$tradeNo = 'YOHOBuy_' . $orderCode;
$input = new WxPayOrderQuery();
... ... @@ -431,6 +486,7 @@ class PayModel
$payResult = WxPayApi::orderQuery($input);
if (isset($payResult['trade_state']) && $payResult['trade_state'] === 'SUCCESS') {
$log->LogInfo('========微信扫码支付成功========');
$result = array(
'code' => '200',
'message' => 'success'
... ... @@ -457,8 +513,18 @@ class PayModel
);
do {
// 初始化日志
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('========[' . $payResult->orderCode . ']========');
$log->LogInfo(var_export($payResult, true));
$log->LogInfo('===开始调用获取订单详情方式接口,接口方法为app.SpaceOrders.detail===');
$orderInfo = OrderData::getOrderDetail($uid, $payResult->orderCode);
$log->LogInfo('===结束调用获取订单详情方式接口,返回结果为===');
$log->LogInfo(var_export($orderInfo, true));
if (!isset($orderInfo['data']) || empty($orderInfo['data'])) {
$log->LogInfo('===订单支付失败,未获取到订单详情信息===');
break;
}
... ... @@ -470,7 +536,14 @@ class PayModel
// 订单已取消
if ($orderData['is_cancel'] === 'Y' && $paymentStatus === 'N') {
// 给用户发送短信
PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode);
// 初始化日志
$log = new PhpLog(self::SEND_MESSAGE_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===[' . $orderCode . ']===');
$log->LogInfo('===开始调用订单取消时给用户发短信接口,接口方法为app.message.sendMsg===');
$messageReturn = PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode);
$log->LogInfo('===结束调用给用户发短信接口,返回结果为===');
$log->LogInfo(var_export($messageReturn, true));
$result['code'] = 417;
$result['message'] = '支付成功,但订单已取消,需联系客服';
break;
... ... @@ -478,6 +551,8 @@ class PayModel
// 支付金额与订单金额不一致
if (round($amount, 2) != round($payResult->totalFee, 2)) {
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===订单支付失败,支付金额与订单金额不一致===');
$result['code'] = 415;
$result['message'] = '支付金额与订单金额不一致';
break;
... ... @@ -489,10 +564,25 @@ class PayModel
$bankBillNo = $payResult->bankBillNo ? $payResult->bankBillNo : "";
$bankName = $payResult->bankName;
$bankCode = $payResult->bankCode;
// 初始化日志
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
$log->LogInfo('===[' . $orderCode . ']===');
$log->LogInfo('===开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');
$log->LogInfo('===请求参数为orderCode=' . $orderCode . '===');
// ERP提交订单状态
PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $payOrderCode, $tradeNo, $bankBillNo);
$erpReturn = PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $payOrderCode, $tradeNo, $bankBillNo);
$log->LogInfo('===结束调用ERP提交订单状态接口,返回结果为===');
$log->LogInfo(var_export($erpReturn, true));
$log->LogInfo('===开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');
$log->LogInfo('===请求参数为orderId=' . $orderData['order_id'] . 'uid=' . $uid . '===');
// 更新订单的状态
PayData::updateOrderStatus($orderData['order_id'], $uid, $payment, 'Y', $bankCode);
$updateOrderStatus = PayData::updateOrderStatus($orderData['order_id'], $uid, $payment, 'Y', $bankCode);
$log->LogInfo('===结束调用更新订单状态接口,返回结果为===');
$log->LogInfo(var_export($updateOrderStatus, true));
$log->LogInfo('===订单支付成功,请等待发货===');
$result['code'] = 200;
$result['message'] = '支付成功,请等待发货';
... ...
... ... @@ -200,8 +200,6 @@ class NoticeController extends WebAction
*/
public function shengpayreturnAction()
{
// $strData = '{"Amount":"0.01","PayAmount":"0.01","OrderNo":"1070021504","serialno":"B000110726001873577","Status":"01","MerchantNo":"408258","PayChannel":"04","Discount":"1","SignType":"2","PayTime":"20110726162126","CurrencyType":"RMB","ProductNo":"","ProductDesc":"","Remark1":"","Remark2":"","ExInfo":"bankid:SDTBNK","Branch":"SHB","MAC":"8ABC0FBAA3EE3202F16A915B42571B58"}';
// $pars = json_decode($strData, true);
$payment = PayModel::getPaymentById(11);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_POST);
... ... @@ -299,6 +297,25 @@ class NoticeController extends WebAction
$this->payResultProc($res, 25);
echo "OK";
}
exit();
}
/**
* 支付宝手机支付(极简)的返回
*/
public function alimobilenoticeminiAction()
{
$payment = PayModel::getPaymentById(20);
$payService = PayFactory::factory($payment);
$res = $payService->parseResponse($_POST); //支付宝通知使用的
if ($res->payResult != -1) {
$this->payResultProc($res, 20);
echo "OK";
} else {
echo 'faile';
}
exit();
}
... ...