洞察掌握android电视app开发中的安全与合规策略,提升企业运营效率
271
2024-06-03
微信支付v3版本小程序支付 php签名,验签,数据解密代码分享
微信支付v3版 php解密解密代码
数据解密需要用到sodium扩展 大部分php版本需要安装
证书序列号可以在这里查看https://myssl.com/cert_decode.html
我用的php7.4版本
直接上代码:
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//微信原生支付
class Wxpay
{
/*
* 支付(小程序支付)
* @param type $sn 订单编号
* @param type $money 金额
* @param type $openid 用户小程序openid
* @return type
*/
public static function getPayParam($sn, $money, $openid)
{
$url = 'https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi';
$notify_url = url('/api/weixin/notify');
$data = [];
$data['appid'] = Action::config(CONFIG_WXXCX, 'app_id');
$data['mchid'] = Action::config(CONFIG_WXXCX, 'mchid'); //商户号
$data['description'] = 'xxx'; //描述?
$data['out_trade_no'] = $sn; //商户系统内部订单号
$data['time_expire'] = date('Y-m-d') . 'T' . date('H:i:s', (time() + 1800)) . '+08:00'; //订单失效时间2018-06-08T10:34:56+08:00
$data['notify_url'] = $notify_url; //异步通知接口地址
$data['amount'] = ['total' => $money * 100, 'currency' => 'CNY']; //金额
$data['payer'] = ['openid' => $openid]; //用户
$re = self::wxCurl($url, $data, 'POST');
if (!isset($re['prepay_id'])) {
api_fail('参数获取失败');
}
$result = [];
$result['appId'] = Action::config(CONFIG_WXXCX, 'app_id');
$result['timeStamp'] = (string)time();
$result['nonceStr'] = uniqid();
$result['package'] = 'prepay_id=' . $re['prepay_id'];
$result['signType'] = 'RSA';
$result['paySign'] = self::getPaySign($result);
return $result;
}
/**
* 查询订单
* @param type $sn
*/
public static function select($sn, $return = false)
{
$mchid = Action::config(CONFIG_WXXCX, 'mchid'); //商户号
$url = 'https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/' . $sn . '?mchid=' . $mchid;
$re = self::wxCurl($url, [], 'GET');
if ($return) {
return $re;
}
if (isset($re['trade_state']) && $re['trade_state'] == 'SUCCESS') {
return true;
}
return false;
}
/**
* 关闭订单
* @param type $sn
*/
public static function close($sn)
{
$mchid = Action::config(CONFIG_WXXCX, 'mchid'); //商户号
$url = 'https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/' . $sn . '/close';
$re = self::wxCurl($url, ['mchid'=>$mchid], 'POST');
return true;
}
/**
* 退款
* @param type $sn
*/
public static function refund($order_sn,$refund_sn,$total,$refund,$msg='退款')
{
$url='https://api.mch.weixin.qq.com/v3/refund/domestic/refunds';
$data=[];
$data['notify_url']=url('ag/weixin/notify_refund');
$data['out_trade_no']=$order_sn;//订单号
$data['out_refund_no']=$refund_sn;//退款单号
$data['reason']=$msg;
$data['amount']=['refund'=>$refund*100,'total'=>$total*100,'currency'=>'CNY'];
$re = self::wxCurl($url, $data, 'POST');
return $re;
}
//请求
public static function wxCurl($url, $data = [], $method = 'GET')
{
$Authorization = self::getReSign($url, $data, $method);
$header = [
'Content-Type: application/json',
'Accept: application/json',
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.63',
'Authorization: ' . $Authorization
];
$redata = $data ? json_encode($data) : '';
$res = reCurl($url, $redata
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~