Service.php
4.34 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
<?php
namespace WebPlugin\Pay\Unionpayweb;
use WebPlugin\Pay\PayAbstract;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\UdpLog;
use WebPlugin\Helpers;
class Service extends PayAbstract
{
private $merId;
public function __construct(array $paymentParams)
{
include_once 'conf/release/SDKConfig.php';
include_once 'Func/common.php';
include_once 'Func/secureUtil.php';
$this->merId = array(
'mobile' => '898111453110482',//手机支付
'pc_nocard' => '898111453110464',//无卡支付
'pc_bank' => '898111453110466'//网银支付
);
}
/**
* 解析返回的参数
*
* @param array $package
* @return bool|string
*/
public function parseResponse(array $package)
{
UdpLog::info("【{$this->logProjectPrefix}-银联支付】,function:parseResponse,参数", $package);
$verify = false;
$responseData = new Rspparams();
if (!isset($package['respCode']) || $package['respCode'] !== '00') {
$responseData->payResult = -1;
return $responseData;
}
if (isset($package['signature'])) { // TODO isset($package['signature']) && verify($package)验证签名待做
$verify = true;
}
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;
}
UdpLog::info("【{$this->logProjectPrefix}-银联支付】,function:parseResponse,处理结果", $responseData);
return $responseData;
}
//https://open.unionpay.com/ajweb/help/faq/list?id=38&level=0&from=0
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' => Helpers::getHttpOrHttps() . Helpers::url(SDK_FRONT_NOTIFY_URL), //前台通知地址--同步地址
'backUrl' => SERVICE_NOTIFY . 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支付暂时不起作用
// 'payTimeout' => '',//超时时间
'reqReserved' => $params->goodsName //请求方保留域,透传字段,查询、通知、对账文件中均会原样出现
);
// 签名
sign($requestParams);
// 前台请求地址
$result = array(
'pay_url' => SDK_FRONT_TRANS_URL,
'pars' => $requestParams,
'reqType' => 'post'
);
UdpLog::info("【{$this->logProjectPrefix}-银联支付】,orderCode:{$params->orderCode},function:getPayRequestPars,处理结果", $result);
return $result;
}
}