Service.php
4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace WebPlugin\Pay\Unionpayweb;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\PhpLog;
use WebPlugin\Helpers;
use Api\Yohobuy;
class Service extends PayAbstract
{
private $merId;
private $log;
public function __construct(array $paymentParams)
{
$env = (APPLICATION_ENV === 'production' || APPLICATION_ENV === 'preview') ? 'release' : 'test';
include_once 'conf/' . $env . '/SDKConfig.php';
include_once 'Func/common.php';
include_once 'Func/secureUtil.php';
$this->log = new PhpLog(SDK_LOG_FILE_PATH, "PRC", SDK_LOG_LEVEL);
$this->merId = array(
'mobile' => '898111453110482',//手机支付
'pc_nocard' => '898111453110464',//无卡支付
'pc_bank' => '898111453110466'//网银支付
);
}
/**
* 解析返回的参数
*
* @param array $package
* @return bool|string
*/
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('银联支付返回码有误');
$responseData->payResult = -1;
return $responseData;
}
if (isset($package['signature'])) { // TODO isset($package['signature']) && verify($package)验证签名待做
$verify = true;
$this->log->LogInfo('银联支付验签成功');
}
if ($verify) {
//更改订单状态
$responseData->orderCode = $package['orderId'];
$responseData->payResult = 200;
$responseData->payTime = time();
$responseData->totalFee = $package['txnAmt'] * 0.01;
$responseData->bankName = '';
$responseData->bankCode = '';
//添加支付订单号和交易号
$responseData->payOrderCode = $package['orderId'];
$responseData->tradeNo = $package['queryId'];
$responseData->bankBillNo = "";
} else {
$responseData->payResult = -1;
}
$this->log->LogInfo("===银联支付的回调参数处理结果为===");
$this->log->LogInfo(var_export($responseData, true));
return $responseData;
}
public function getPayRequestPars(Reqparams $params)
{
$front_notify_url = SDK_FRONT_NOTIFY_URL . '?order_code=' . $params->orderCode;
$requestParams = array(
'version' => '5.0.0', //版本号
'encoding' => 'utf-8', //编码方式
'certId' => getSignCertId(), //证书ID
'txnType' => '01', //交易类型
'txnSubType' => '01', //交易子类
'bizType' => '000201', //业务类型
'frontUrl' => $front_notify_url, //前台通知地址--同步地址
'backUrl' => SDK_BACK_NOTIFY_URL,//后台通知地址--异步地址
'signMethod' => '01', //签名方法
'channelType' => '07', //渠道类型,07-PC,08-手机
'accessType' => '0', //接入类型
'merId' => $this->merId['pc_bank'], //商户代码,请改自己的测试商户号
'orderId' => $params->orderCode, //商户订单号
'txnTime' => date('YmdHis', $params->orderTime), //订单发送时间
'txnAmt' => $params->totalFee, //交易金额,单位分
'currencyCode' => '156', //交易币种
'defaultPayType' => '0201', //默认支付方式
//'orderDesc' => '订单描述', //订单描述,网关支付和wap支付暂时不起作用
'reqReserved' => $params->goodsName //请求方保留域,透传字段,查询、通知、对账文件中均会原样出现
);
// 签名
sign($requestParams);
// 前台请求地址
$result = array(
'pay_url' => SDK_FRONT_TRANS_URL,
'pars' => $requestParams,
'reqType' => 'post'
);
$this->log->LogInfo(var_export($requestParams, true));
return $result;
}
}