├── readme.txt
├── weixinAPPpay
├── wechatAppPay.php
└── wxapp.php
├── weixinH5pay
├── h5.php
├── wechatH5Pay.php
└── wxh5.php
├── weixinJSAPIpay
├── WxPay.Api.php
├── WxPay.Config.php
├── WxPay.Data.php
├── WxPay.Exception.php
├── WxPay.JsApiPay.php
├── js.php
├── jsapi.php
└── native.php
├── weixinNATIVEpay
├── WxPay.Api.php
├── WxPay.Config.php
├── WxPay.Data.php
├── WxPay.Exception.php
├── WxPay.NativePay.php
└── native.php
└── weixinNOTIFY
├── notify.php
└── wechatAppPay.php
/readme.txt:
--------------------------------------------------------------------------------
1 | APPpay------微信app支付(在你的app程序中唤醒微信app进行支付,前台交接用的是hbuilder)
2 | H5pay-------非微信内置浏览器打开微信支付(返回的数据放到h5.php中)
3 | JSAPIpay----微信内置浏览器打开微信支付(返回的数据放到js.php中)(最麻烦的一个,需要设置支付授权目录;还要去公众号里面设置网页授权域名;而且不能用泛解析域名,必须用备案上边的写的域名)
4 | NATIVEpay---电脑端扫码支付 返回一个二维码地址(放到自己做的支付页面中)
5 | NOTIFY------支付完成后的异步通知(可以在这修改订单状态啥的)
6 | 有什么问题可以添加的qq咨询(qq:785900782)
--------------------------------------------------------------------------------
/weixinAPPpay/wechatAppPay.php:
--------------------------------------------------------------------------------
1 | //填写微信分配的公众账号ID
8 | * 'mch_id' => //填写微信支付分配的商户号
9 | * 'notify_url'=> //填写微信支付结果回调地址
10 | * 'key' => //填写微信商户支付密钥
11 | * );
12 | * 统一下单方法
13 | * $WechatAppPay = new wechatAppPay($options);
14 | * $params['body'] = '商品描述'; //商品描述
15 | * $params['out_trade_no'] = '1217752501201407'; //自定义的订单号,不能重复
16 | * $params['total_fee'] = '100'; //订单金额 只能为整数 单位为分
17 | * $params['trade_type'] = 'APP'; //交易类型 JSAPI | NATIVE |APP | WAP
18 | * $wechatAppPay->unifiedOrder( $params );
19 | */
20 | class wechatAppPay
21 | {
22 | //接口API URL前缀
23 | const API_URL_PREFIX = 'https://api.mch.weixin.qq.com';
24 | //下单地址URL
25 | const UNIFIEDORDER_URL = "/pay/unifiedorder";
26 | //查询订单URL
27 | const ORDERQUERY_URL = "/pay/orderquery";
28 | //关闭订单URL
29 | const CLOSEORDER_URL = "/pay/closeorder";
30 | //公众账号ID
31 | private $appid;
32 | //商户号
33 | private $mch_id;
34 | //随机字符串
35 | private $nonce_str;
36 | //签名
37 | private $sign;
38 | //商品描述
39 | private $body;
40 | //商户订单号
41 | private $out_trade_no;
42 | //支付总金额
43 | private $total_fee;
44 | //终端IP
45 | private $spbill_create_ip;
46 | //支付结果回调通知地址
47 | private $notify_url;
48 | //交易类型
49 | private $trade_type;
50 | //支付密钥
51 | private $key;
52 | //证书路径
53 | private $SSLCERT_PATH;
54 | private $SSLKEY_PATH;
55 | //所有参数
56 | private $params = array();
57 | public function __construct($appid, $mch_id, $notify_url, $key)
58 | {
59 | $this->appid = $appid;
60 | $this->mch_id = $mch_id;
61 | $this->notify_url = $notify_url;
62 | $this->key = $key;
63 | }
64 | /**
65 | * 下单方法
66 | * @param $params 下单参数
67 | */
68 | public function unifiedOrder( $params ){
69 | $this->body = $params['body'];
70 | $this->out_trade_no = $params['out_trade_no'];
71 | $this->total_fee = $params['total_fee'];
72 | $this->trade_type = $params['trade_type'];
73 | $this->nonce_str = $this->genRandomString();
74 | $this->spbill_create_ip = $_SERVER['REMOTE_ADDR'];
75 | $this->params['appid'] = $this->appid;
76 | $this->params['mch_id'] = $this->mch_id;
77 | $this->params['nonce_str'] = $this->nonce_str;
78 | $this->params['body'] = $this->body;
79 | $this->params['out_trade_no'] = $this->out_trade_no;
80 | $this->params['total_fee'] = $this->total_fee;
81 | $this->params['spbill_create_ip'] = $this->spbill_create_ip;
82 | $this->params['notify_url'] = $this->notify_url;
83 | $this->params['trade_type'] = $this->trade_type;
84 | //获取签名数据
85 | $this->sign = $this->MakeSign( $this->params );
86 | $this->params['sign'] = $this->sign;
87 | $xml = $this->data_to_xml($this->params);
88 | $response = $this->postXmlCurl($xml, self::API_URL_PREFIX.self::UNIFIEDORDER_URL);
89 | if( !$response ){
90 | return false;
91 | }
92 | $result = $this->xml_to_data( $response );
93 | if( !empty($result['result_code']) && !empty($result['err_code']) ){
94 | $result['err_msg'] = $this->error_code( $result['err_code'] );
95 | }
96 | return $result;
97 | }
98 | /**
99 | * 查询订单信息
100 | * @param $out_trade_no 订单号
101 | * @return array
102 | */
103 | public function orderQuery( $out_trade_no ){
104 | $this->params['appid'] = $this->appid;
105 | $this->params['mch_id'] = $this->mch_id;
106 | $this->params['nonce_str'] = $this->genRandomString();
107 | $this->params['out_trade_no'] = $out_trade_no;
108 | //获取签名数据
109 | $this->sign = $this->MakeSign( $this->params );
110 | $this->params['sign'] = $this->sign;
111 | $xml = $this->data_to_xml($this->params);
112 | $response = $this->postXmlCurl($xml, self::API_URL_PREFIX.self::ORDERQUERY_URL);
113 | if( !$response ){
114 | return false;
115 | }
116 | $result = $this->xml_to_data( $response );
117 | if( !empty($result['result_code']) && !empty($result['err_code']) ){
118 | $result['err_msg'] = $this->error_code( $result['err_code'] );
119 | }
120 | return $result;
121 | }
122 | /**
123 | * 关闭订单
124 | * @param $out_trade_no 订单号
125 | * @return array
126 | */
127 | public function closeOrder( $out_trade_no ){
128 | $this->params['appid'] = $this->appid;
129 | $this->params['mch_id'] = $this->mch_id;
130 | $this->params['nonce_str'] = $this->genRandomString();
131 | $this->params['out_trade_no'] = $out_trade_no;
132 | //获取签名数据
133 | $this->sign = $this->MakeSign( $this->params );
134 | $this->params['sign'] = $this->sign;
135 | $xml = $this->data_to_xml($this->params);
136 | $response = $this->postXmlCurl($xml, self::API_URL_PREFIX.self::CLOSEORDER_URL);
137 | if( !$response ){
138 | return false;
139 | }
140 | $result = $this->xml_to_data( $response );
141 | return $result;
142 | }
143 | /**
144 | *
145 | * 获取支付结果通知数据
146 | * return array
147 | */
148 | public function getNotifyData(){
149 | //获取通知的数据
150 | $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
151 | //echo 123;die;
152 | $data = array();
153 | if( empty($xml) ){
154 | return false;
155 | }
156 | $data = $this->xml_to_data( $xml );
157 | if( !empty($data['return_code']) ){
158 | if( $data['return_code'] == 'FAIL' ){
159 | return false;
160 | }
161 | }
162 | return $data;
163 | }
164 | /**
165 | * 接收通知成功后应答输出XML数据
166 | * @param string $xml
167 | */
168 | public function replyNotify(){
169 | $data['return_code'] = 'SUCCESS';
170 | $data['return_msg'] = 'OK';
171 | $xml = $this->data_to_xml( $data );
172 | echo $xml;
173 | die();
174 | }
175 | /**
176 | * 生成APP端支付参数
177 | * @param $prepayid 预支付id
178 | */
179 | public function getAppPayParams( $prepayid ){
180 | $data['appid'] = $this->appid;
181 | $data['partnerid'] = $this->mch_id;
182 | $data['prepayid'] = $prepayid;
183 | $data['package'] = 'Sign=WXPay';
184 | $data['noncestr'] = $this->genRandomString();
185 | $data['timestamp'] = time();
186 | $data['sign'] = $this->MakeSign( $data );
187 | return $data;
188 | }
189 | /**
190 | * 生成签名
191 | * @return 签名
192 | */
193 | public function MakeSign( $params ){
194 | //签名步骤一:按字典序排序数组参数
195 | ksort($params);
196 | $string = $this->ToUrlParams($params);
197 | //签名步骤二:在string后加入KEY
198 | $string = $string . "&key=".$this->key;
199 | //签名步骤三:MD5加密
200 | $string = md5($string);
201 | //签名步骤四:所有字符转为大写
202 | $result = strtoupper($string);
203 | return $result;
204 | }
205 | /**
206 | * 将参数拼接为url: key=value&key=value
207 | * @param $params
208 | * @return string
209 | */
210 | public function ToUrlParams( $params ){
211 | $string = '';
212 | if( !empty($params) ){
213 | $array = array();
214 | foreach( $params as $key => $value ){
215 | $array[] = $key.'='.$value;
216 | }
217 | $string = implode("&",$array);
218 | }
219 | return $string;
220 | }
221 | /**
222 | * 输出xml字符
223 | * @param $params 参数名称
224 | * return string 返回组装的xml
225 | **/
226 | public function data_to_xml( $params ){
227 | if(!is_array($params)|| count($params) <= 0)
228 | {
229 | return false;
230 | }
231 | $xml = "";
232 | foreach ($params as $key=>$val)
233 | {
234 | if (is_numeric($val)){
235 | $xml.="<".$key.">".$val."".$key.">";
236 | }else{
237 | $xml.="<".$key.">".$key.">";
238 | }
239 | }
240 | $xml.="";
241 | return $xml;
242 | }
243 | /**
244 | * 将xml转为array
245 | * @param string $xml
246 | * return array
247 | */
248 | public function xml_to_data($xml){
249 | if(!$xml){
250 | return false;
251 | }
252 | //将XML转为array
253 | //禁止引用外部xml实体
254 | libxml_disable_entity_loader(true);
255 | $data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
256 | return $data;
257 | }
258 | /**
259 | * 获取毫秒级别的时间戳
260 | */
261 | private static function getMillisecond(){
262 | //获取毫秒的时间戳
263 | $time = explode ( " ", microtime () );
264 | $time = $time[1] . ($time[0] * 1000);
265 | $time2 = explode( ".", $time );
266 | $time = $time2[0];
267 | return $time;
268 | }
269 | /**
270 | * 产生一个指定长度的随机字符串,并返回给用户
271 | * @param type $len 产生字符串的长度
272 | * @return string 随机字符串
273 | */
274 | private function genRandomString($len = 32) {
275 | $chars = array(
276 | "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
277 | "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
278 | "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
279 | "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
280 | "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
281 | "3", "4", "5", "6", "7", "8", "9"
282 | );
283 | $charsLen = count($chars) - 1;
284 | // 将数组打乱
285 | shuffle($chars);
286 | $output = "";
287 | for ($i = 0; $i < $len; $i++) {
288 | $output .= $chars[mt_rand(0, $charsLen)];
289 | }
290 | return $output;
291 | }
292 | /**
293 | * 以post方式提交xml到对应的接口url
294 | *
295 | * @param string $xml 需要post的xml数据
296 | * @param string $url url
297 | * @param bool $useCert 是否需要证书,默认不需要
298 | * @param int $second url执行超时时间,默认30s
299 | * @throws WxPayException
300 | */
301 | private function postXmlCurl($xml, $url, $useCert = false, $second = 30){
302 | $ch = curl_init();
303 | //设置超时
304 | curl_setopt($ch, CURLOPT_TIMEOUT, $second);
305 | curl_setopt($ch,CURLOPT_URL, $url);
306 | curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
307 | curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);
308 | //设置header
309 | curl_setopt($ch, CURLOPT_HEADER, FALSE);
310 | //要求结果为字符串且输出到屏幕上
311 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
312 | if($useCert == true){
313 | //设置证书
314 | //使用证书:cert 与 key 分别属于两个.pem文件
315 | curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
316 | //curl_setopt($ch,CURLOPT_SSLCERT, WxPayConfig::SSLCERT_PATH);
317 | curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
318 | //curl_setopt($ch,CURLOPT_SSLKEY, WxPayConfig::SSLKEY_PATH);
319 | }
320 | //post提交方式
321 | curl_setopt($ch, CURLOPT_POST, TRUE);
322 | curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
323 | //运行curl
324 | $data = curl_exec($ch);
325 | //返回结果
326 | if($data){
327 | curl_close($ch);
328 | return $data;
329 | } else {
330 | $error = curl_errno($ch);
331 | curl_close($ch);
332 | return false;
333 | }
334 | }
335 | /**
336 | * 错误代码
337 | * @param $code 服务器输出的错误代码
338 | * return string
339 | */
340 | public function error_code( $code ){
341 | $errList = array(
342 | 'NOAUTH' => '商户未开通此接口权限',
343 | 'NOTENOUGH' => '用户帐号余额不足',
344 | 'ORDERNOTEXIST' => '订单号不存在',
345 | 'ORDERPAID' => '商户订单已支付,无需重复操作',
346 | 'ORDERCLOSED' => '当前订单已关闭,无法支付',
347 | 'SYSTEMERROR' => '系统错误!系统超时',
348 | 'APPID_NOT_EXIST' => '参数中缺少APPID',
349 | 'MCHID_NOT_EXIST' => '参数中缺少MCHID',
350 | 'APPID_MCHID_NOT_MATCH' => 'appid和mch_id不匹配',
351 | 'LACK_PARAMS' => '缺少必要的请求参数',
352 | 'OUT_TRADE_NO_USED' => '同一笔交易不能多次提交',
353 | 'SIGNERROR' => '参数签名结果不正确',
354 | 'XML_FORMAT_ERROR' => 'XML格式错误',
355 | 'REQUIRE_POST_METHOD' => '未使用post传递参数 ',
356 | 'POST_DATA_EMPTY' => 'post数据不能为空',
357 | 'NOT_UTF8' => '未使用指定编码格式',
358 | );
359 | if( array_key_exists( $code , $errList ) ){
360 | return $errList[$code];
361 | }
362 | }
363 | }
364 |
365 |
366 |
367 |
368 |
369 |
--------------------------------------------------------------------------------
/weixinAPPpay/wxapp.php:
--------------------------------------------------------------------------------
1 | unifiedOrder( $params );
16 | /** @var TYPE_NAME $result */
17 | $data = @$wechatAppPay->getAppPayParams( $result['prepay_id'] );
18 |
19 | //print_r($data);die;
20 |
21 | return json_encode($data);
22 | }
23 | }
24 |
25 | ?>
--------------------------------------------------------------------------------
/weixinH5pay/h5.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 微信支付样例-支付
6 |
7 |
8 |
9 | 该笔订单支付金额为1分钱
10 |
13 |
14 |
--------------------------------------------------------------------------------
/weixinH5pay/wechatH5Pay.php:
--------------------------------------------------------------------------------
1 | //填写微信分配的公众账号ID
9 | * 'mch_id' => //填写微信支付分配的商户号
10 | * 'notify_url'=> //填写微信支付结果回调地址
11 | * 'key' => //填写微信商户支付密钥
12 | * );
13 | * 统一下单方法
14 | * $WechatAppPay = new wechatAppPay($options);
15 | * $params['body'] = '商品描述'; //商品描述
16 | * $params['out_trade_no'] = '1217752501201407'; //自定义的订单号,不能重复
17 | * $params['total_fee'] = '100'; //订单金额 只能为整数 单位为分
18 | * $params['trade_type'] = 'APP'; //交易类型 JSAPI | NATIVE |APP | WAP
19 | * $wechatAppPay->unifiedOrder( $params );
20 | */
21 | class wechatAppPay
22 | {
23 | //接口API URL前缀
24 | const API_URL_PREFIX = 'https://api.mch.weixin.qq.com';
25 | //下单地址URL
26 | const UNIFIEDORDER_URL = "/pay/unifiedorder";
27 | //查询订单URL
28 | const ORDERQUERY_URL = "/pay/orderquery";
29 | //关闭订单URL
30 | const CLOSEORDER_URL = "/pay/closeorder";
31 | //公众账号ID
32 | private $appid;
33 | //商户号
34 | private $mch_id;
35 | //随机字符串
36 | private $nonce_str;
37 | //签名
38 | private $sign;
39 | //商品描述
40 | private $body;
41 | //商户订单号
42 | private $out_trade_no;
43 | //支付总金额
44 | private $total_fee;
45 | //终端IP
46 | private $spbill_create_ip;
47 | //支付结果回调通知地址
48 | private $notify_url;
49 | //交易类型
50 | private $trade_type;
51 | //支付密钥
52 | private $key;
53 | //证书路径
54 | private $SSLCERT_PATH;
55 | private $SSLKEY_PATH;
56 | //所有参数
57 | private $params = array();
58 | public function __construct($appid, $mch_id, $notify_url, $key)
59 | {
60 | $this->appid = $appid;
61 | $this->mch_id = $mch_id;
62 | $this->notify_url = $notify_url;
63 | $this->key = $key;
64 | }
65 | /**
66 | * 下单方法
67 | * @param $params 下单参数
68 | */
69 | public function unifiedOrder( $params ){
70 | $this->body = $params['body'];
71 | $this->out_trade_no = $params['out_trade_no'];
72 | $this->total_fee = $params['total_fee'];
73 | $this->trade_type = $params['trade_type'];
74 | $this->scene_info = $params['scene_info'];
75 | $this->nonce_str = $this->genRandomString();
76 | $this->spbill_create_ip = $_SERVER['REMOTE_ADDR'];
77 | $this->params['appid'] = $this->appid;
78 | $this->params['mch_id'] = $this->mch_id;
79 | $this->params['nonce_str'] = $this->nonce_str;
80 | $this->params['body'] = $this->body;
81 | $this->params['out_trade_no'] = $this->out_trade_no;
82 | $this->params['total_fee'] = $this->total_fee;
83 | $this->params['spbill_create_ip'] = $this->spbill_create_ip;
84 | $this->params['notify_url'] = $this->notify_url;
85 | $this->params['trade_type'] = $this->trade_type;
86 | $this->params['scene_info'] = $this->scene_info;
87 | //获取签名数据
88 | $this->sign = $this->MakeSign( $this->params );
89 | $this->params['sign'] = $this->sign;
90 | $xml = $this->data_to_xml($this->params);
91 | $response = $this->postXmlCurl($xml, self::API_URL_PREFIX.self::UNIFIEDORDER_URL);
92 | if( !$response ){
93 | return false;
94 | }
95 | $result = $this->xml_to_data( $response );
96 | if( !empty($result['result_code']) && !empty($result['err_code']) ){
97 | $result['err_msg'] = $this->error_code( $result['err_code'] );
98 | }
99 | return $result;
100 | }
101 | /**
102 | * 查询订单信息
103 | * @param $out_trade_no 订单号
104 | * @return array
105 | */
106 | public function orderQuery( $out_trade_no ){
107 | $this->params['appid'] = $this->appid;
108 | $this->params['mch_id'] = $this->mch_id;
109 | $this->params['nonce_str'] = $this->genRandomString();
110 | $this->params['out_trade_no'] = $out_trade_no;
111 | //获取签名数据
112 | $this->sign = $this->MakeSign( $this->params );
113 | $this->params['sign'] = $this->sign;
114 | $xml = $this->data_to_xml($this->params);
115 | $response = $this->postXmlCurl($xml, self::API_URL_PREFIX.self::ORDERQUERY_URL);
116 | if( !$response ){
117 | return false;
118 | }
119 | $result = $this->xml_to_data( $response );
120 | if( !empty($result['result_code']) && !empty($result['err_code']) ){
121 | $result['err_msg'] = $this->error_code( $result['err_code'] );
122 | }
123 | return $result;
124 | }
125 | /**
126 | * 关闭订单
127 | * @param $out_trade_no 订单号
128 | * @return array
129 | */
130 | public function closeOrder( $out_trade_no ){
131 | $this->params['appid'] = $this->appid;
132 | $this->params['mch_id'] = $this->mch_id;
133 | $this->params['nonce_str'] = $this->genRandomString();
134 | $this->params['out_trade_no'] = $out_trade_no;
135 | //获取签名数据
136 | $this->sign = $this->MakeSign( $this->params );
137 | $this->params['sign'] = $this->sign;
138 | $xml = $this->data_to_xml($this->params);
139 | $response = $this->postXmlCurl($xml, self::API_URL_PREFIX.self::CLOSEORDER_URL);
140 | if( !$response ){
141 | return false;
142 | }
143 | $result = $this->xml_to_data( $response );
144 | return $result;
145 | }
146 | /**
147 | *
148 | * 获取支付结果通知数据
149 | * return array
150 | */
151 | public function getNotifyData(){
152 | //获取通知的数据
153 | $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
154 | //echo 123;die;
155 | $data = array();
156 | if( empty($xml) ){
157 | return false;
158 | }
159 | $data = $this->xml_to_data( $xml );
160 | if( !empty($data['return_code']) ){
161 | if( $data['return_code'] == 'FAIL' ){
162 | return false;
163 | }
164 | }
165 | return $data;
166 | }
167 | /**
168 | * 接收通知成功后应答输出XML数据
169 | * @param string $xml
170 | */
171 | public function replyNotify(){
172 | $data['return_code'] = 'SUCCESS';
173 | $data['return_msg'] = 'OK';
174 | $xml = $this->data_to_xml( $data );
175 | echo $xml;
176 | die();
177 | }
178 | /**
179 | * 生成APP端支付参数
180 | * @param $prepayid 预支付id
181 | */
182 | public function getAppPayParams( $prepayid ){
183 | $data['appid'] = $this->appid;
184 | $data['partnerid'] = $this->mch_id;
185 | $data['prepayid'] = $prepayid;
186 | $data['package'] = 'Sign=WXPay';
187 | $data['noncestr'] = $this->genRandomString();
188 | $data['timestamp'] = time();
189 | $data['sign'] = $this->MakeSign( $data );
190 | return $data;
191 | }
192 | /**
193 | * 生成签名
194 | * @return 签名
195 | */
196 | public function MakeSign( $params ){
197 | //签名步骤一:按字典序排序数组参数
198 | ksort($params);
199 | $string = $this->ToUrlParams($params);
200 | //签名步骤二:在string后加入KEY
201 | $string = $string . "&key=".$this->key;
202 | //签名步骤三:MD5加密
203 | $string = md5($string);
204 | //签名步骤四:所有字符转为大写
205 | $result = strtoupper($string);
206 | return $result;
207 | }
208 | /**
209 | * 将参数拼接为url: key=value&key=value
210 | * @param $params
211 | * @return string
212 | */
213 | public function ToUrlParams( $params ){
214 | $string = '';
215 | if( !empty($params) ){
216 | $array = array();
217 | foreach( $params as $key => $value ){
218 | $array[] = $key.'='.$value;
219 | }
220 | $string = implode("&",$array);
221 | }
222 | return $string;
223 | }
224 | /**
225 | * 输出xml字符
226 | * @param $params 参数名称
227 | * return string 返回组装的xml
228 | **/
229 | public function data_to_xml( $params ){
230 | if(!is_array($params)|| count($params) <= 0)
231 | {
232 | return false;
233 | }
234 | $xml = "";
235 | foreach ($params as $key=>$val)
236 | {
237 | if (is_numeric($val)){
238 | $xml.="<".$key.">".$val."".$key.">";
239 | }else{
240 | $xml.="<".$key.">".$key.">";
241 | }
242 | }
243 | $xml.="";
244 | return $xml;
245 | }
246 | /**
247 | * 将xml转为array
248 | * @param string $xml
249 | * return array
250 | */
251 | public function xml_to_data($xml){
252 | if(!$xml){
253 | return false;
254 | }
255 | //将XML转为array
256 | //禁止引用外部xml实体
257 | libxml_disable_entity_loader(true);
258 | $data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
259 | return $data;
260 | }
261 | /**
262 | * 获取毫秒级别的时间戳
263 | */
264 | private static function getMillisecond(){
265 | //获取毫秒的时间戳
266 | $time = explode ( " ", microtime () );
267 | $time = $time[1] . ($time[0] * 1000);
268 | $time2 = explode( ".", $time );
269 | $time = $time2[0];
270 | return $time;
271 | }
272 | /**
273 | * 产生一个指定长度的随机字符串,并返回给用户
274 | * @param type $len 产生字符串的长度
275 | * @return string 随机字符串
276 | */
277 | private function genRandomString($len = 32) {
278 | $chars = array(
279 | "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
280 | "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
281 | "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
282 | "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
283 | "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
284 | "3", "4", "5", "6", "7", "8", "9"
285 | );
286 | $charsLen = count($chars) - 1;
287 | // 将数组打乱
288 | shuffle($chars);
289 | $output = "";
290 | for ($i = 0; $i < $len; $i++) {
291 | $output .= $chars[mt_rand(0, $charsLen)];
292 | }
293 | return $output;
294 | }
295 | /**
296 | * 以post方式提交xml到对应的接口url
297 | *
298 | * @param string $xml 需要post的xml数据
299 | * @param string $url url
300 | * @param bool $useCert 是否需要证书,默认不需要
301 | * @param int $second url执行超时时间,默认30s
302 | * @throws WxPayException
303 | */
304 | private function postXmlCurl($xml, $url, $useCert = false, $second = 30){
305 | $ch = curl_init();
306 | //设置超时
307 | curl_setopt($ch, CURLOPT_TIMEOUT, $second);
308 | curl_setopt($ch,CURLOPT_URL, $url);
309 | curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
310 | curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);
311 | //设置header
312 | curl_setopt($ch, CURLOPT_HEADER, FALSE);
313 | //要求结果为字符串且输出到屏幕上
314 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
315 | if($useCert == true){
316 | //设置证书
317 | //使用证书:cert 与 key 分别属于两个.pem文件
318 | curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
319 | //curl_setopt($ch,CURLOPT_SSLCERT, WxPayConfig::SSLCERT_PATH);
320 | curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
321 | //curl_setopt($ch,CURLOPT_SSLKEY, WxPayConfig::SSLKEY_PATH);
322 | }
323 | //post提交方式
324 | curl_setopt($ch, CURLOPT_POST, TRUE);
325 | curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
326 | //运行curl
327 | $data = curl_exec($ch);
328 | //返回结果
329 | if($data){
330 | curl_close($ch);
331 | return $data;
332 | } else {
333 | $error = curl_errno($ch);
334 | curl_close($ch);
335 | return false;
336 | }
337 | }
338 | /**
339 | * 错误代码
340 | * @param $code 服务器输出的错误代码
341 | * return string
342 | */
343 | public function error_code( $code ){
344 | $errList = array(
345 | 'NOAUTH' => '商户未开通此接口权限',
346 | 'NOTENOUGH' => '用户帐号余额不足',
347 | 'ORDERNOTEXIST' => '订单号不存在',
348 | 'ORDERPAID' => '商户订单已支付,无需重复操作',
349 | 'ORDERCLOSED' => '当前订单已关闭,无法支付',
350 | 'SYSTEMERROR' => '系统错误!系统超时',
351 | 'APPID_NOT_EXIST' => '参数中缺少APPID',
352 | 'MCHID_NOT_EXIST' => '参数中缺少MCHID',
353 | 'APPID_MCHID_NOT_MATCH' => 'appid和mch_id不匹配',
354 | 'LACK_PARAMS' => '缺少必要的请求参数',
355 | 'OUT_TRADE_NO_USED' => '同一笔交易不能多次提交',
356 | 'SIGNERROR' => '参数签名结果不正确',
357 | 'XML_FORMAT_ERROR' => 'XML格式错误',
358 | 'REQUIRE_POST_METHOD' => '未使用post传递参数 ',
359 | 'POST_DATA_EMPTY' => 'post数据不能为空',
360 | 'NOT_UTF8' => '未使用指定编码格式',
361 | );
362 | if( array_key_exists( $code , $errList ) ){
363 | return $errList[$code];
364 | }
365 | }
366 | }
367 |
368 |
369 |
370 |
371 |
372 |
--------------------------------------------------------------------------------
/weixinH5pay/wxh5.php:
--------------------------------------------------------------------------------
1 | unifiedOrder( $params );
18 | $url = $result['mweb_url'].'&redirect_url=https%3A%2F%2Fapi.lanhaitools.com/wap
19 | ';//redirect_url 是支付完成后返回的页面
20 | return $url;
21 | }
22 | }
23 |
24 | ?>
--------------------------------------------------------------------------------
/weixinJSAPIpay/WxPay.Api.php:
--------------------------------------------------------------------------------
1 | IsOut_trade_noSet()) {
29 | throw new WxPayException("缺少统一支付接口必填参数out_trade_no!");
30 | }else if(!$inputObj->IsBodySet()){
31 | throw new WxPayException("缺少统一支付接口必填参数body!");
32 | }else if(!$inputObj->IsTotal_feeSet()) {
33 | throw new WxPayException("缺少统一支付接口必填参数total_fee!");
34 | }else if(!$inputObj->IsTrade_typeSet()) {
35 | throw new WxPayException("缺少统一支付接口必填参数trade_type!");
36 | }
37 |
38 | //关联参数
39 | if($inputObj->GetTrade_type() == "JSAPI" && !$inputObj->IsOpenidSet()){
40 | throw new WxPayException("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!");
41 | }
42 | if($inputObj->GetTrade_type() == "NATIVE" && !$inputObj->IsProduct_idSet()){
43 | throw new WxPayException("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
44 | }
45 |
46 | //异步通知url未设置,则使用配置文件中的url
47 | if(!$inputObj->IsNotify_urlSet()){
48 | $inputObj->SetNotify_url(WxPayConfig::NOTIFY_URL);//异步通知url
49 | }
50 |
51 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
52 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
53 | $inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
54 | //$inputObj->SetSpbill_create_ip("1.1.1.1");
55 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
56 |
57 | //签名
58 | $inputObj->SetSign();
59 | $xml = $inputObj->ToXml();
60 | $startTimeStamp = self::getMillisecond();//请求开始时间
61 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
62 | //echo $response;die;
63 | $result = WxPayResults::Init($response);
64 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
65 |
66 | return $result;
67 | }
68 |
69 | /**
70 | *
71 | * 查询订单,WxPayOrderQuery中out_trade_no、transaction_id至少填一个
72 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
73 | * @param WxPayOrderQuery $inputObj
74 | * @param int $timeOut
75 | * @throws WxPayException
76 | * @return 成功时返回,其他抛异常
77 | */
78 | public static function orderQuery($inputObj, $timeOut = 6)
79 | {
80 | $url = "https://api.mch.weixin.qq.com/pay/orderquery";
81 | //检测必填参数
82 | if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
83 | throw new WxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!");
84 | }
85 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
86 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
87 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
88 |
89 | $inputObj->SetSign();//签名
90 | $xml = $inputObj->ToXml();
91 |
92 | $startTimeStamp = self::getMillisecond();//请求开始时间
93 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
94 | $result = WxPayResults::Init($response);
95 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
96 |
97 | return $result;
98 | }
99 |
100 | /**
101 | *
102 | * 关闭订单,WxPayCloseOrder中out_trade_no必填
103 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
104 | * @param WxPayCloseOrder $inputObj
105 | * @param int $timeOut
106 | * @throws WxPayException
107 | * @return 成功时返回,其他抛异常
108 | */
109 | public static function closeOrder($inputObj, $timeOut = 6)
110 | {
111 | $url = "https://api.mch.weixin.qq.com/pay/closeorder";
112 | //检测必填参数
113 | if(!$inputObj->IsOut_trade_noSet()) {
114 | throw new WxPayException("订单查询接口中,out_trade_no必填!");
115 | }
116 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
117 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
118 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
119 |
120 | $inputObj->SetSign();//签名
121 | $xml = $inputObj->ToXml();
122 |
123 | $startTimeStamp = self::getMillisecond();//请求开始时间
124 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
125 | $result = WxPayResults::Init($response);
126 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
127 |
128 | return $result;
129 | }
130 |
131 | /**
132 | *
133 | * 申请退款,WxPayRefund中out_trade_no、transaction_id至少填一个且
134 | * out_refund_no、total_fee、refund_fee、op_user_id为必填参数
135 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
136 | * @param WxPayRefund $inputObj
137 | * @param int $timeOut
138 | * @throws WxPayException
139 | * @return 成功时返回,其他抛异常
140 | */
141 | public static function refund($inputObj, $timeOut = 6)
142 | {
143 | $url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
144 | //检测必填参数
145 | if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
146 | throw new WxPayException("退款申请接口中,out_trade_no、transaction_id至少填一个!");
147 | }else if(!$inputObj->IsOut_refund_noSet()){
148 | throw new WxPayException("退款申请接口中,缺少必填参数out_refund_no!");
149 | }else if(!$inputObj->IsTotal_feeSet()){
150 | throw new WxPayException("退款申请接口中,缺少必填参数total_fee!");
151 | }else if(!$inputObj->IsRefund_feeSet()){
152 | throw new WxPayException("退款申请接口中,缺少必填参数refund_fee!");
153 | }else if(!$inputObj->IsOp_user_idSet()){
154 | throw new WxPayException("退款申请接口中,缺少必填参数op_user_id!");
155 | }
156 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
157 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
158 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
159 |
160 | $inputObj->SetSign();//签名
161 | $xml = $inputObj->ToXml();
162 | $startTimeStamp = self::getMillisecond();//请求开始时间
163 | $response = self::postXmlCurl($xml, $url, true, $timeOut);
164 | $result = WxPayResults::Init($response);
165 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
166 |
167 | return $result;
168 | }
169 |
170 | /**
171 | *
172 | * 查询退款
173 | * 提交退款申请后,通过调用该接口查询退款状态。退款有一定延时,
174 | * 用零钱支付的退款20分钟内到账,银行卡支付的退款3个工作日后重新查询退款状态。
175 | * WxPayRefundQuery中out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个
176 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
177 | * @param WxPayRefundQuery $inputObj
178 | * @param int $timeOut
179 | * @throws WxPayException
180 | * @return 成功时返回,其他抛异常
181 | */
182 | public static function refundQuery($inputObj, $timeOut = 6)
183 | {
184 | $url = "https://api.mch.weixin.qq.com/pay/refundquery";
185 | //检测必填参数
186 | if(!$inputObj->IsOut_refund_noSet() &&
187 | !$inputObj->IsOut_trade_noSet() &&
188 | !$inputObj->IsTransaction_idSet() &&
189 | !$inputObj->IsRefund_idSet()) {
190 | throw new WxPayException("退款查询接口中,out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个!");
191 | }
192 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
193 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
194 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
195 |
196 | $inputObj->SetSign();//签名
197 | $xml = $inputObj->ToXml();
198 |
199 | $startTimeStamp = self::getMillisecond();//请求开始时间
200 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
201 | $result = WxPayResults::Init($response);
202 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
203 |
204 | return $result;
205 | }
206 |
207 | /**
208 | * 下载对账单,WxPayDownloadBill中bill_date为必填参数
209 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
210 | * @param WxPayDownloadBill $inputObj
211 | * @param int $timeOut
212 | * @throws WxPayException
213 | * @return 成功时返回,其他抛异常
214 | */
215 | public static function downloadBill($inputObj, $timeOut = 6)
216 | {
217 | $url = "https://api.mch.weixin.qq.com/pay/downloadbill";
218 | //检测必填参数
219 | if(!$inputObj->IsBill_dateSet()) {
220 | throw new WxPayException("对账单接口中,缺少必填参数bill_date!");
221 | }
222 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
223 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
224 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
225 |
226 | $inputObj->SetSign();//签名
227 | $xml = $inputObj->ToXml();
228 |
229 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
230 | if(substr($response, 0 , 5) == ""){
231 | return "";
232 | }
233 | return $response;
234 | }
235 |
236 | /**
237 | * 提交被扫支付API
238 | * 收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台,
239 | * 由商户收银台或者商户后台调用该接口发起支付。
240 | * WxPayWxPayMicroPay中body、out_trade_no、total_fee、auth_code参数必填
241 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
242 | * @param WxPayWxPayMicroPay $inputObj
243 | * @param int $timeOut
244 | */
245 | public static function micropay($inputObj, $timeOut = 10)
246 | {
247 | $url = "https://api.mch.weixin.qq.com/pay/micropay";
248 | //检测必填参数
249 | if(!$inputObj->IsBodySet()) {
250 | throw new WxPayException("提交被扫支付API接口中,缺少必填参数body!");
251 | } else if(!$inputObj->IsOut_trade_noSet()) {
252 | throw new WxPayException("提交被扫支付API接口中,缺少必填参数out_trade_no!");
253 | } else if(!$inputObj->IsTotal_feeSet()) {
254 | throw new WxPayException("提交被扫支付API接口中,缺少必填参数total_fee!");
255 | } else if(!$inputObj->IsAuth_codeSet()) {
256 | throw new WxPayException("提交被扫支付API接口中,缺少必填参数auth_code!");
257 | }
258 |
259 | $inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
260 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
261 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
262 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
263 |
264 | $inputObj->SetSign();//签名
265 | $xml = $inputObj->ToXml();
266 |
267 | $startTimeStamp = self::getMillisecond();//请求开始时间
268 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
269 | $result = WxPayResults::Init($response);
270 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
271 |
272 | return $result;
273 | }
274 |
275 | /**
276 | *
277 | * 撤销订单API接口,WxPayReverse中参数out_trade_no和transaction_id必须填写一个
278 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
279 | * @param WxPayReverse $inputObj
280 | * @param int $timeOut
281 | * @throws WxPayException
282 | */
283 | public static function reverse($inputObj, $timeOut = 6)
284 | {
285 | $url = "https://api.mch.weixin.qq.com/secapi/pay/reverse";
286 | //检测必填参数
287 | if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
288 | throw new WxPayException("撤销订单API接口中,参数out_trade_no和transaction_id必须填写一个!");
289 | }
290 |
291 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
292 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
293 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
294 |
295 | $inputObj->SetSign();//签名
296 | $xml = $inputObj->ToXml();
297 |
298 | $startTimeStamp = self::getMillisecond();//请求开始时间
299 | $response = self::postXmlCurl($xml, $url, true, $timeOut);
300 | $result = WxPayResults::Init($response);
301 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
302 |
303 | return $result;
304 | }
305 |
306 | /**
307 | *
308 | * 测速上报,该方法内部封装在report中,使用时请注意异常流程
309 | * WxPayReport中interface_url、return_code、result_code、user_ip、execute_time_必填
310 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
311 | * @param WxPayReport $inputObj
312 | * @param int $timeOut
313 | * @throws WxPayException
314 | * @return 成功时返回,其他抛异常
315 | */
316 | public static function report($inputObj, $timeOut = 1)
317 | {
318 | $url = "https://api.mch.weixin.qq.com/payitil/report";
319 | //检测必填参数
320 | if(!$inputObj->IsInterface_urlSet()) {
321 | throw new WxPayException("接口URL,缺少必填参数interface_url!");
322 | } if(!$inputObj->IsReturn_codeSet()) {
323 | throw new WxPayException("返回状态码,缺少必填参数return_code!");
324 | } if(!$inputObj->IsResult_codeSet()) {
325 | throw new WxPayException("业务结果,缺少必填参数result_code!");
326 | } if(!$inputObj->IsUser_ipSet()) {
327 | throw new WxPayException("访问接口IP,缺少必填参数user_ip!");
328 | } if(!$inputObj->IsExecute_time_Set()) {
329 | throw new WxPayException("接口耗时,缺少必填参数execute_time_!");
330 | }
331 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
332 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
333 | $inputObj->SetUser_ip($_SERVER['REMOTE_ADDR']);//终端ip
334 | $inputObj->SetTime(date("YmdHis"));//商户上报时间
335 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
336 |
337 | $inputObj->SetSign();//签名
338 | $xml = $inputObj->ToXml();
339 |
340 | $startTimeStamp = self::getMillisecond();//请求开始时间
341 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
342 | return $response;
343 | }
344 |
345 | /**
346 | *
347 | * 生成二维码规则,模式一生成支付二维码
348 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
349 | * @param WxPayBizPayUrl $inputObj
350 | * @param int $timeOut
351 | * @throws WxPayException
352 | * @return 成功时返回,其他抛异常
353 | */
354 | public static function bizpayurl($inputObj, $timeOut = 6)
355 | {
356 | if(!$inputObj->IsProduct_idSet()){
357 | throw new WxPayException("生成二维码,缺少必填参数product_id!");
358 | }
359 |
360 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
361 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
362 | $inputObj->SetTime_stamp(time());//时间戳
363 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
364 |
365 | $inputObj->SetSign();//签名
366 |
367 | return $inputObj->GetValues();
368 | }
369 |
370 | /**
371 | *
372 | * 转换短链接
373 | * 该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),
374 | * 减小二维码数据量,提升扫描速度和精确度。
375 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
376 | * @param WxPayShortUrl $inputObj
377 | * @param int $timeOut
378 | * @throws WxPayException
379 | * @return 成功时返回,其他抛异常
380 | */
381 | public static function shorturl($inputObj, $timeOut = 6)
382 | {
383 | $url = "https://api.mch.weixin.qq.com/tools/shorturl";
384 | //检测必填参数
385 | if(!$inputObj->IsLong_urlSet()) {
386 | throw new WxPayException("需要转换的URL,签名用原串,传输需URL encode!");
387 | }
388 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
389 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
390 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
391 |
392 | $inputObj->SetSign();//签名
393 | $xml = $inputObj->ToXml();
394 |
395 | $startTimeStamp = self::getMillisecond();//请求开始时间
396 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
397 | $result = WxPayResults::Init($response);
398 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
399 |
400 | return $result;
401 | }
402 |
403 | /**
404 | *
405 | * 支付结果通用通知
406 | * @param function $callback
407 | * 直接回调函数使用方法: notify(you_function);
408 | * 回调类成员函数方法:notify(array($this, you_function));
409 | * $callback 原型为:function function_name($data){}
410 | */
411 | public static function notify($callback, &$msg)
412 | {
413 | //获取通知的数据
414 | $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
415 | //如果返回成功则验证签名
416 | try {
417 | $result = WxPayResults::Init($xml);
418 | } catch (WxPayException $e){
419 | $msg = $e->errorMessage();
420 | return false;
421 | }
422 |
423 | return call_user_func($callback, $result);
424 | }
425 |
426 | /**
427 | *
428 | * 产生随机字符串,不长于32位
429 | * @param int $length
430 | * @return 产生的随机字符串
431 | */
432 | public static function getNonceStr($length = 32)
433 | {
434 | $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
435 | $str ="";
436 | for ( $i = 0; $i < $length; $i++ ) {
437 | $str .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
438 | }
439 | return $str;
440 | }
441 |
442 | /**
443 | * 直接输出xml
444 | * @param string $xml
445 | */
446 | public static function replyNotify($xml)
447 | {
448 | echo $xml;
449 | }
450 |
451 | /**
452 | *
453 | * 上报数据, 上报的时候将屏蔽所有异常流程
454 | * @param string $usrl
455 | * @param int $startTimeStamp
456 | * @param array $data
457 | */
458 | private static function reportCostTime($url, $startTimeStamp, $data)
459 | {
460 | //如果不需要上报数据
461 | if(WxPayConfig::REPORT_LEVENL == 0){
462 | return;
463 | }
464 | //如果仅失败上报
465 | if(WxPayConfig::REPORT_LEVENL == 1 &&
466 | array_key_exists("return_code", $data) &&
467 | $data["return_code"] == "SUCCESS" &&
468 | array_key_exists("result_code", $data) &&
469 | $data["result_code"] == "SUCCESS")
470 | {
471 | return;
472 | }
473 |
474 | //上报逻辑
475 | $endTimeStamp = self::getMillisecond();
476 | $objInput = new WxPayReport();
477 | $objInput->SetInterface_url($url);
478 | $objInput->SetExecute_time_($endTimeStamp - $startTimeStamp);
479 | //返回状态码
480 | if(array_key_exists("return_code", $data)){
481 | $objInput->SetReturn_code($data["return_code"]);
482 | }
483 | //返回信息
484 | if(array_key_exists("return_msg", $data)){
485 | $objInput->SetReturn_msg($data["return_msg"]);
486 | }
487 | //业务结果
488 | if(array_key_exists("result_code", $data)){
489 | $objInput->SetResult_code($data["result_code"]);
490 | }
491 | //错误代码
492 | if(array_key_exists("err_code", $data)){
493 | $objInput->SetErr_code($data["err_code"]);
494 | }
495 | //错误代码描述
496 | if(array_key_exists("err_code_des", $data)){
497 | $objInput->SetErr_code_des($data["err_code_des"]);
498 | }
499 | //商户订单号
500 | if(array_key_exists("out_trade_no", $data)){
501 | $objInput->SetOut_trade_no($data["out_trade_no"]);
502 | }
503 | //设备号
504 | if(array_key_exists("device_info", $data)){
505 | $objInput->SetDevice_info($data["device_info"]);
506 | }
507 |
508 | try{
509 | self::report($objInput);
510 | } catch (WxPayException $e){
511 | //不做任何处理
512 | }
513 | }
514 |
515 | /**
516 | * 以post方式提交xml到对应的接口url
517 | *
518 | * @param string $xml 需要post的xml数据
519 | * @param string $url url
520 | * @param bool $useCert 是否需要证书,默认不需要
521 | * @param int $second url执行超时时间,默认30s
522 | * @throws WxPayException
523 | */
524 | private static function postXmlCurl($xml, $url, $useCert = false, $second = 30)
525 | {
526 | $ch = curl_init();
527 | //设置超时
528 | curl_setopt($ch, CURLOPT_TIMEOUT, $second);
529 |
530 | //如果有配置代理这里就设置代理
531 | if(WxPayConfig::CURL_PROXY_HOST != "0.0.0.0"
532 | && WxPayConfig::CURL_PROXY_PORT != 0){
533 | curl_setopt($ch,CURLOPT_PROXY, WxPayConfig::CURL_PROXY_HOST);
534 | curl_setopt($ch,CURLOPT_PROXYPORT, WxPayConfig::CURL_PROXY_PORT);
535 | }
536 | curl_setopt($ch,CURLOPT_URL, $url);
537 | //curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE);
538 | curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);//2017-05-26 修改
539 | //curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);//严格校验
540 | curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);//严格校验
541 | //设置header
542 | curl_setopt($ch, CURLOPT_HEADER, FALSE);
543 | //要求结果为字符串且输出到屏幕上
544 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
545 |
546 | if($useCert == true){
547 | //设置证书
548 | //使用证书:cert 与 key 分别属于两个.pem文件
549 | curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
550 | curl_setopt($ch,CURLOPT_SSLCERT, WxPayConfig::SSLCERT_PATH);
551 | curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
552 | curl_setopt($ch,CURLOPT_SSLKEY, WxPayConfig::SSLKEY_PATH);
553 | }
554 | //post提交方式
555 | curl_setopt($ch, CURLOPT_POST, TRUE);
556 | curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
557 | //运行curl
558 | $data = curl_exec($ch);
559 | //echo $data;die;
560 | //返回结果
561 | if($data){
562 | //echo '33333333333333';die;
563 | curl_close($ch);
564 | return $data;
565 | } else {
566 | //echo '222222222222';die;
567 | $error = curl_errno($ch);
568 | curl_close($ch);
569 | throw new WxPayException("curl出错,错误码:$error");
570 | }
571 | }
572 |
573 | /**
574 | * 获取毫秒级别的时间戳
575 | */
576 | private static function getMillisecond()
577 | {
578 | //获取毫秒的时间戳
579 | $time = explode ( " ", microtime () );
580 | $time = $time[1] . ($time[0] * 1000);
581 | $time2 = explode( ".", $time );
582 | $time = $time2[0];
583 | return $time;
584 | }
585 | }
586 |
587 |
--------------------------------------------------------------------------------
/weixinJSAPIpay/WxPay.Config.php:
--------------------------------------------------------------------------------
1 | MakeSign();
25 | $this->values['sign'] = $sign;
26 | return $sign;
27 | }
28 |
29 | /**
30 | * 获取签名,详见签名生成算法的值
31 | * @return 值
32 | **/
33 | public function GetSign()
34 | {
35 | return $this->values['sign'];
36 | }
37 |
38 | /**
39 | * 判断签名,详见签名生成算法是否存在
40 | * @return true 或 false
41 | **/
42 | public function IsSignSet()
43 | {
44 | return array_key_exists('sign', $this->values);
45 | }
46 | /**
47 | * 输出xml字符
48 | * @throws WxPayException
49 | **/
50 | public function ToXml()
51 | {
52 | if(!is_array($this->values)
53 | || count($this->values) <= 0)
54 | {
55 | throw new WxPayException("数组数据异常!");
56 | }
57 |
58 | $xml = "";
59 | foreach ($this->values as $key=>$val)
60 | {
61 | if (is_numeric($val)){
62 | $xml.="<".$key.">".$val."".$key.">";
63 | }else{
64 | $xml.="<".$key.">".$key.">";
65 | }
66 | }
67 | $xml.="";
68 | return $xml;
69 | }
70 |
71 | /**
72 | * 将xml转为array
73 | * @param string $xml
74 | * @throws WxPayException
75 | */
76 | public function FromXml($xml)
77 | {
78 | if(!$xml){
79 | throw new WxPayException("xml数据异常!");
80 | }
81 | //将XML转为array
82 | //禁止引用外部xml实体
83 | libxml_disable_entity_loader(true);
84 | $this->values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
85 | return $this->values;
86 | }
87 |
88 | /**
89 | * 格式化参数格式化成url参数
90 | */
91 | public function ToUrlParams()
92 | {
93 | $buff = "";
94 | foreach ($this->values as $k => $v)
95 | {
96 | if($k != "sign" && $v != "" && !is_array($v)){
97 | $buff .= $k . "=" . $v . "&";
98 | }
99 | }
100 |
101 | $buff = trim($buff, "&");
102 | return $buff;
103 | }
104 |
105 | /**
106 | * 生成签名
107 | * @return 签名,本函数不覆盖sign成员变量,如要设置签名需要调用SetSign方法赋值
108 | */
109 | public function MakeSign()
110 | {
111 | //签名步骤一:按字典序排序参数
112 | ksort($this->values);
113 | $string = $this->ToUrlParams();
114 | //签名步骤二:在string后加入KEY
115 | $string = $string . "&key=".WxPayConfig::KEY;
116 | //签名步骤三:MD5加密
117 | $string = md5($string);
118 | //签名步骤四:所有字符转为大写
119 | $result = strtoupper($string);
120 | return $result;
121 | }
122 |
123 | /**
124 | * 获取设置的值
125 | */
126 | public function GetValues()
127 | {
128 | return $this->values;
129 | }
130 | }
131 | /**
132 | *
133 | * 接口调用结果类
134 | * @author widyhu
135 | *
136 | */
137 | class WxPayResults extends WxPayDataBase
138 | {
139 | /**
140 | *
141 | * 检测签名
142 | */
143 | public function CheckSign()
144 | {
145 | //fix异常
146 | if(!$this->IsSignSet()){
147 | throw new WxPayException("签名错误!");
148 | }
149 |
150 | $sign = $this->MakeSign();
151 | if($this->GetSign() == $sign){
152 | return true;
153 | }
154 | throw new WxPayException("签名错误!");
155 | }
156 |
157 | /**
158 | *
159 | * 使用数组初始化
160 | * @param array $array
161 | */
162 | public function FromArray($array)
163 | {
164 | $this->values = $array;
165 | }
166 |
167 | /**
168 | *
169 | * 使用数组初始化对象
170 | * @param array $array
171 | * @param 是否检测签名 $noCheckSign
172 | */
173 | public static function InitFromArray($array, $noCheckSign = false)
174 | {
175 | $obj = new self();
176 | $obj->FromArray($array);
177 | if($noCheckSign == false){
178 | $obj->CheckSign();
179 | }else{
180 | $obj->SetSign();
181 | }
182 | return $obj;
183 | }
184 |
185 | /**
186 | *
187 | * 设置参数
188 | * @param string $key
189 | * @param string $value
190 | */
191 | public function SetData($key, $value)
192 | {
193 | $this->values[$key] = $value;
194 | }
195 |
196 | /**
197 | * 将xml转为array
198 | * @param string $xml
199 | * @throws WxPayException
200 | */
201 | public static function Init($xml)
202 | {
203 | $obj = new self();
204 | $obj->FromXml($xml);
205 | //fix bug 2015-06-29
206 | if($obj->values['return_code'] != 'SUCCESS'){
207 | return $obj->GetValues();
208 | }
209 | $obj->CheckSign();
210 | return $obj->GetValues();
211 | }
212 | }
213 | /**
214 | *
215 | * 回调基础类
216 | * @author widyhu
217 | *
218 | */
219 | class WxPayNotifyReply extends WxPayDataBase
220 | {
221 | /**
222 | *
223 | * 设置错误码 FAIL 或者 SUCCESS
224 | * @param string
225 | */
226 | public function SetReturn_code($return_code)
227 | {
228 | $this->values['return_code'] = $return_code;
229 | }
230 |
231 | /**
232 | *
233 | * 获取错误码 FAIL 或者 SUCCESS
234 | * @return string $return_code
235 | */
236 | public function GetReturn_code()
237 | {
238 | return $this->values['return_code'];
239 | }
240 | /**
241 | *
242 | * 设置错误信息
243 | * @param string $return_code
244 | */
245 | public function SetReturn_msg($return_msg)
246 | {
247 | $this->values['return_msg'] = $return_msg;
248 | }
249 |
250 | /**
251 | *
252 | * 获取错误信息
253 | * @return string
254 | */
255 | public function GetReturn_msg()
256 | {
257 | return $this->values['return_msg'];
258 | }
259 |
260 | /**
261 | *
262 | * 设置返回参数
263 | * @param string $key
264 | * @param string $value
265 | */
266 | public function SetData($key, $value)
267 | {
268 | $this->values[$key] = $value;
269 | }
270 | }
271 | /**
272 | *
273 | * 统一下单输入对象
274 | * @author widyhu
275 | *
276 | */
277 | class WxPayUnifiedOrder extends WxPayDataBase
278 | {
279 | /**
280 | * 设置微信分配的公众账号ID
281 | * @param string $value
282 | **/
283 | public function SetAppid($value)
284 | {
285 | $this->values['appid'] = $value;
286 | }
287 | /**
288 | * 获取微信分配的公众账号ID的值
289 | * @return 值
290 | **/
291 | public function GetAppid()
292 | {
293 | return $this->values['appid'];
294 | }
295 | /**
296 | * 判断微信分配的公众账号ID是否存在
297 | * @return true 或 false
298 | **/
299 | public function IsAppidSet()
300 | {
301 | return array_key_exists('appid', $this->values);
302 | }
303 | /**
304 | * 设置微信支付分配的商户号
305 | * @param string $value
306 | **/
307 | public function SetMch_id($value)
308 | {
309 | $this->values['mch_id'] = $value;
310 | }
311 | /**
312 | * 获取微信支付分配的商户号的值
313 | * @return 值
314 | **/
315 | public function GetMch_id()
316 | {
317 | return $this->values['mch_id'];
318 | }
319 | /**
320 | * 判断微信支付分配的商户号是否存在
321 | * @return true 或 false
322 | **/
323 | public function IsMch_idSet()
324 | {
325 | return array_key_exists('mch_id', $this->values);
326 | }
327 | /**
328 | * 设置微信支付分配的终端设备号,商户自定义
329 | * @param string $value
330 | **/
331 | public function SetDevice_info($value)
332 | {
333 | $this->values['device_info'] = $value;
334 | }
335 | /**
336 | * 获取微信支付分配的终端设备号,商户自定义的值
337 | * @return 值
338 | **/
339 | public function GetDevice_info()
340 | {
341 | return $this->values['device_info'];
342 | }
343 | /**
344 | * 判断微信支付分配的终端设备号,商户自定义是否存在
345 | * @return true 或 false
346 | **/
347 | public function IsDevice_infoSet()
348 | {
349 | return array_key_exists('device_info', $this->values);
350 | }
351 | /**
352 | * 设置随机字符串,不长于32位。推荐随机数生成算法
353 | * @param string $value
354 | **/
355 | public function SetNonce_str($value)
356 | {
357 | $this->values['nonce_str'] = $value;
358 | }
359 | /**
360 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值
361 | * @return 值
362 | **/
363 | public function GetNonce_str()
364 | {
365 | return $this->values['nonce_str'];
366 | }
367 | /**
368 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
369 | * @return true 或 false
370 | **/
371 | public function IsNonce_strSet()
372 | {
373 | return array_key_exists('nonce_str', $this->values);
374 | }
375 | /**
376 | * 设置商品或支付单简要描述
377 | * @param string $value
378 | **/
379 | public function SetBody($value)
380 | {
381 | $this->values['body'] = $value;
382 | }
383 | /**
384 | * 获取商品或支付单简要描述的值
385 | * @return 值
386 | **/
387 | public function GetBody()
388 | {
389 | return $this->values['body'];
390 | }
391 | /**
392 | * 判断商品或支付单简要描述是否存在
393 | * @return true 或 false
394 | **/
395 | public function IsBodySet()
396 | {
397 | return array_key_exists('body', $this->values);
398 | }
399 | /**
400 | * 设置商品名称明细列表
401 | * @param string $value
402 | **/
403 | public function SetDetail($value)
404 | {
405 | $this->values['detail'] = $value;
406 | }
407 | /**
408 | * 获取商品名称明细列表的值
409 | * @return 值
410 | **/
411 | public function GetDetail()
412 | {
413 | return $this->values['detail'];
414 | }
415 | /**
416 | * 判断商品名称明细列表是否存在
417 | * @return true 或 false
418 | **/
419 | public function IsDetailSet()
420 | {
421 | return array_key_exists('detail', $this->values);
422 | }
423 | /**
424 | * 设置附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
425 | * @param string $value
426 | **/
427 | public function SetAttach($value)
428 | {
429 | $this->values['attach'] = $value;
430 | }
431 | /**
432 | * 获取附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据的值
433 | * @return 值
434 | **/
435 | public function GetAttach()
436 | {
437 | return $this->values['attach'];
438 | }
439 | /**
440 | * 判断附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据是否存在
441 | * @return true 或 false
442 | **/
443 | public function IsAttachSet()
444 | {
445 | return array_key_exists('attach', $this->values);
446 | }
447 | /**
448 | * 设置商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
449 | * @param string $value
450 | **/
451 | public function SetOut_trade_no($value)
452 | {
453 | $this->values['out_trade_no'] = $value;
454 | }
455 | /**
456 | * 获取商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号的值
457 | * @return 值
458 | **/
459 | public function GetOut_trade_no()
460 | {
461 | return $this->values['out_trade_no'];
462 | }
463 | /**
464 | * 判断商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号是否存在
465 | * @return true 或 false
466 | **/
467 | public function IsOut_trade_noSet()
468 | {
469 | return array_key_exists('out_trade_no', $this->values);
470 | }
471 | /**
472 | * 设置符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
473 | * @param string $value
474 | **/
475 | public function SetFee_type($value)
476 | {
477 | $this->values['fee_type'] = $value;
478 | }
479 | /**
480 | * 获取符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型的值
481 | * @return 值
482 | **/
483 | public function GetFee_type()
484 | {
485 | return $this->values['fee_type'];
486 | }
487 | /**
488 | * 判断符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型是否存在
489 | * @return true 或 false
490 | **/
491 | public function IsFee_typeSet()
492 | {
493 | return array_key_exists('fee_type', $this->values);
494 | }
495 | /**
496 | * 设置订单总金额,只能为整数,详见支付金额
497 | * @param string $value
498 | **/
499 | public function SetTotal_fee($value)
500 | {
501 | $this->values['total_fee'] = $value;
502 | }
503 | /**
504 | * 获取订单总金额,只能为整数,详见支付金额的值
505 | * @return 值
506 | **/
507 | public function GetTotal_fee()
508 | {
509 | return $this->values['total_fee'];
510 | }
511 | /**
512 | * 判断订单总金额,只能为整数,详见支付金额是否存在
513 | * @return true 或 false
514 | **/
515 | public function IsTotal_feeSet()
516 | {
517 | return array_key_exists('total_fee', $this->values);
518 | }
519 | /**
520 | * 设置APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。
521 | * @param string $value
522 | **/
523 | public function SetSpbill_create_ip($value)
524 | {
525 | $this->values['spbill_create_ip'] = $value;
526 | }
527 | /**
528 | * 获取APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。的值
529 | * @return 值
530 | **/
531 | public function GetSpbill_create_ip()
532 | {
533 | return $this->values['spbill_create_ip'];
534 | }
535 | /**
536 | * 判断APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。是否存在
537 | * @return true 或 false
538 | **/
539 | public function IsSpbill_create_ipSet()
540 | {
541 | return array_key_exists('spbill_create_ip', $this->values);
542 | }
543 | /**
544 | * 设置订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
545 | * @param string $value
546 | **/
547 | public function SetTime_start($value)
548 | {
549 | $this->values['time_start'] = $value;
550 | }
551 | /**
552 | * 获取订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则的值
553 | * @return 值
554 | **/
555 | public function GetTime_start()
556 | {
557 | return $this->values['time_start'];
558 | }
559 | /**
560 | * 判断订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则是否存在
561 | * @return true 或 false
562 | **/
563 | public function IsTime_startSet()
564 | {
565 | return array_key_exists('time_start', $this->values);
566 | }
567 | /**
568 | * 设置订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则
569 | * @param string $value
570 | **/
571 | public function SetTime_expire($value)
572 | {
573 | $this->values['time_expire'] = $value;
574 | }
575 | /**
576 | * 获取订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则的值
577 | * @return 值
578 | **/
579 | public function GetTime_expire()
580 | {
581 | return $this->values['time_expire'];
582 | }
583 | /**
584 | * 判断订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则是否存在
585 | * @return true 或 false
586 | **/
587 | public function IsTime_expireSet()
588 | {
589 | return array_key_exists('time_expire', $this->values);
590 | }
591 | /**
592 | * 设置商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠
593 | * @param string $value
594 | **/
595 | public function SetGoods_tag($value)
596 | {
597 | $this->values['goods_tag'] = $value;
598 | }
599 | /**
600 | * 获取商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠的值
601 | * @return 值
602 | **/
603 | public function GetGoods_tag()
604 | {
605 | return $this->values['goods_tag'];
606 | }
607 | /**
608 | * 判断商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠是否存在
609 | * @return true 或 false
610 | **/
611 | public function IsGoods_tagSet()
612 | {
613 | return array_key_exists('goods_tag', $this->values);
614 | }
615 | /**
616 | * 设置接收微信支付异步通知回调地址
617 | * @param string $value
618 | **/
619 | public function SetNotify_url($value)
620 | {
621 | $this->values['notify_url'] = $value;
622 | }
623 | /**
624 | * 获取接收微信支付异步通知回调地址的值
625 | * @return 值
626 | **/
627 | public function GetNotify_url()
628 | {
629 | return $this->values['notify_url'];
630 | }
631 | /**
632 | * 判断接收微信支付异步通知回调地址是否存在
633 | * @return true 或 false
634 | **/
635 | public function IsNotify_urlSet()
636 | {
637 | return array_key_exists('notify_url', $this->values);
638 | }
639 | /**
640 | * 设置取值如下:JSAPI,NATIVE,APP,详细说明见参数规定
641 | * @param string $value
642 | **/
643 | public function SetTrade_type($value)
644 | {
645 | $this->values['trade_type'] = $value;
646 | }
647 | /**
648 | * 获取取值如下:JSAPI,NATIVE,APP,详细说明见参数规定的值
649 | * @return 值
650 | **/
651 | public function GetTrade_type()
652 | {
653 | return $this->values['trade_type'];
654 | }
655 | /**
656 | * 判断取值如下:JSAPI,NATIVE,APP,详细说明见参数规定是否存在
657 | * @return true 或 false
658 | **/
659 | public function IsTrade_typeSet()
660 | {
661 | return array_key_exists('trade_type', $this->values);
662 | }
663 | /**
664 | * 设置trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
665 | * @param string $value
666 | **/
667 | public function SetProduct_id($value)
668 | {
669 | $this->values['product_id'] = $value;
670 | }
671 | /**
672 | * 获取trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。的值
673 | * @return 值
674 | **/
675 | public function GetProduct_id()
676 | {
677 | return $this->values['product_id'];
678 | }
679 | /**
680 | * 判断trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。是否存在
681 | * @return true 或 false
682 | **/
683 | public function IsProduct_idSet()
684 | {
685 | return array_key_exists('product_id', $this->values);
686 | }
687 | /**
688 | * 设置trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。下单前需要调用【网页授权获取用户信息】接口获取到用户的Openid。
689 | * @param string $value
690 | **/
691 | public function SetOpenid($value)
692 | {
693 | $this->values['openid'] = $value;
694 | }
695 | /**
696 | * 获取trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。下单前需要调用【网页授权获取用户信息】接口获取到用户的Openid。 的值
697 | * @return 值
698 | **/
699 | public function GetOpenid()
700 | {
701 | return $this->values['openid'];
702 | }
703 | /**
704 | * 判断trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。下单前需要调用【网页授权获取用户信息】接口获取到用户的Openid。 是否存在
705 | * @return true 或 false
706 | **/
707 | public function IsOpenidSet()
708 | {
709 | return array_key_exists('openid', $this->values);
710 | }
711 | }
712 | /**
713 | *
714 | * 订单查询输入对象
715 | * @author widyhu
716 | *
717 | */
718 | class WxPayOrderQuery extends WxPayDataBase
719 | {
720 | /**
721 | * 设置微信分配的公众账号ID
722 | * @param string $value
723 | **/
724 | public function SetAppid($value)
725 | {
726 | $this->values['appid'] = $value;
727 | }
728 | /**
729 | * 获取微信分配的公众账号ID的值
730 | * @return 值
731 | **/
732 | public function GetAppid()
733 | {
734 | return $this->values['appid'];
735 | }
736 | /**
737 | * 判断微信分配的公众账号ID是否存在
738 | * @return true 或 false
739 | **/
740 | public function IsAppidSet()
741 | {
742 | return array_key_exists('appid', $this->values);
743 | }
744 | /**
745 | * 设置微信支付分配的商户号
746 | * @param string $value
747 | **/
748 | public function SetMch_id($value)
749 | {
750 | $this->values['mch_id'] = $value;
751 | }
752 | /**
753 | * 获取微信支付分配的商户号的值
754 | * @return 值
755 | **/
756 | public function GetMch_id()
757 | {
758 | return $this->values['mch_id'];
759 | }
760 | /**
761 | * 判断微信支付分配的商户号是否存在
762 | * @return true 或 false
763 | **/
764 | public function IsMch_idSet()
765 | {
766 | return array_key_exists('mch_id', $this->values);
767 | }
768 | /**
769 | * 设置微信的订单号,优先使用
770 | * @param string $value
771 | **/
772 | public function SetTransaction_id($value)
773 | {
774 | $this->values['transaction_id'] = $value;
775 | }
776 | /**
777 | * 获取微信的订单号,优先使用的值
778 | * @return 值
779 | **/
780 | public function GetTransaction_id()
781 | {
782 | return $this->values['transaction_id'];
783 | }
784 | /**
785 | * 判断微信的订单号,优先使用是否存在
786 | * @return true 或 false
787 | **/
788 | public function IsTransaction_idSet()
789 | {
790 | return array_key_exists('transaction_id', $this->values);
791 | }
792 | /**
793 | * 设置商户系统内部的订单号,当没提供transaction_id时需要传这个。
794 | * @param string $value
795 | **/
796 | public function SetOut_trade_no($value)
797 | {
798 | $this->values['out_trade_no'] = $value;
799 | }
800 | /**
801 | * 获取商户系统内部的订单号,当没提供transaction_id时需要传这个。的值
802 | * @return 值
803 | **/
804 | public function GetOut_trade_no()
805 | {
806 | return $this->values['out_trade_no'];
807 | }
808 | /**
809 | * 判断商户系统内部的订单号,当没提供transaction_id时需要传这个。是否存在
810 | * @return true 或 false
811 | **/
812 | public function IsOut_trade_noSet()
813 | {
814 | return array_key_exists('out_trade_no', $this->values);
815 | }
816 | /**
817 | * 设置随机字符串,不长于32位。推荐随机数生成算法
818 | * @param string $value
819 | **/
820 | public function SetNonce_str($value)
821 | {
822 | $this->values['nonce_str'] = $value;
823 | }
824 | /**
825 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值
826 | * @return 值
827 | **/
828 | public function GetNonce_str()
829 | {
830 | return $this->values['nonce_str'];
831 | }
832 | /**
833 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
834 | * @return true 或 false
835 | **/
836 | public function IsNonce_strSet()
837 | {
838 | return array_key_exists('nonce_str', $this->values);
839 | }
840 | }
841 | /**
842 | *
843 | * 关闭订单输入对象
844 | * @author widyhu
845 | *
846 | */
847 | class WxPayCloseOrder extends WxPayDataBase
848 | {
849 | /**
850 | * 设置微信分配的公众账号ID
851 | * @param string $value
852 | **/
853 | public function SetAppid($value)
854 | {
855 | $this->values['appid'] = $value;
856 | }
857 | /**
858 | * 获取微信分配的公众账号ID的值
859 | * @return 值
860 | **/
861 | public function GetAppid()
862 | {
863 | return $this->values['appid'];
864 | }
865 | /**
866 | * 判断微信分配的公众账号ID是否存在
867 | * @return true 或 false
868 | **/
869 | public function IsAppidSet()
870 | {
871 | return array_key_exists('appid', $this->values);
872 | }
873 | /**
874 | * 设置微信支付分配的商户号
875 | * @param string $value
876 | **/
877 | public function SetMch_id($value)
878 | {
879 | $this->values['mch_id'] = $value;
880 | }
881 | /**
882 | * 获取微信支付分配的商户号的值
883 | * @return 值
884 | **/
885 | public function GetMch_id()
886 | {
887 | return $this->values['mch_id'];
888 | }
889 | /**
890 | * 判断微信支付分配的商户号是否存在
891 | * @return true 或 false
892 | **/
893 | public function IsMch_idSet()
894 | {
895 | return array_key_exists('mch_id', $this->values);
896 | }
897 | /**
898 | * 设置商户系统内部的订单号
899 | * @param string $value
900 | **/
901 | public function SetOut_trade_no($value)
902 | {
903 | $this->values['out_trade_no'] = $value;
904 | }
905 | /**
906 | * 获取商户系统内部的订单号的值
907 | * @return 值
908 | **/
909 | public function GetOut_trade_no()
910 | {
911 | return $this->values['out_trade_no'];
912 | }
913 | /**
914 | * 判断商户系统内部的订单号是否存在
915 | * @return true 或 false
916 | **/
917 | public function IsOut_trade_noSet()
918 | {
919 | return array_key_exists('out_trade_no', $this->values);
920 | }
921 | /**
922 | * 设置商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
923 | * @param string $value
924 | **/
925 | public function SetNonce_str($value)
926 | {
927 | $this->values['nonce_str'] = $value;
928 | }
929 | /**
930 | * 获取商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号的值
931 | * @return 值
932 | **/
933 | public function GetNonce_str()
934 | {
935 | return $this->values['nonce_str'];
936 | }
937 | /**
938 | * 判断商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号是否存在
939 | * @return true 或 false
940 | **/
941 | public function IsNonce_strSet()
942 | {
943 | return array_key_exists('nonce_str', $this->values);
944 | }
945 | }
946 | /**
947 | *
948 | * 提交退款输入对象
949 | * @author widyhu
950 | *
951 | */
952 | class WxPayRefund extends WxPayDataBase
953 | {
954 | /**
955 | * 设置微信分配的公众账号ID
956 | * @param string $value
957 | **/
958 | public function SetAppid($value)
959 | {
960 | $this->values['appid'] = $value;
961 | }
962 | /**
963 | * 获取微信分配的公众账号ID的值
964 | * @return 值
965 | **/
966 | public function GetAppid()
967 | {
968 | return $this->values['appid'];
969 | }
970 | /**
971 | * 判断微信分配的公众账号ID是否存在
972 | * @return true 或 false
973 | **/
974 | public function IsAppidSet()
975 | {
976 | return array_key_exists('appid', $this->values);
977 | }
978 | /**
979 | * 设置微信支付分配的商户号
980 | * @param string $value
981 | **/
982 | public function SetMch_id($value)
983 | {
984 | $this->values['mch_id'] = $value;
985 | }
986 | /**
987 | * 获取微信支付分配的商户号的值
988 | * @return 值
989 | **/
990 | public function GetMch_id()
991 | {
992 | return $this->values['mch_id'];
993 | }
994 | /**
995 | * 判断微信支付分配的商户号是否存在
996 | * @return true 或 false
997 | **/
998 | public function IsMch_idSet()
999 | {
1000 | return array_key_exists('mch_id', $this->values);
1001 | }
1002 | /**
1003 | * 设置微信支付分配的终端设备号,与下单一致
1004 | * @param string $value
1005 | **/
1006 | public function SetDevice_info($value)
1007 | {
1008 | $this->values['device_info'] = $value;
1009 | }
1010 | /**
1011 | * 获取微信支付分配的终端设备号,与下单一致的值
1012 | * @return 值
1013 | **/
1014 | public function GetDevice_info()
1015 | {
1016 | return $this->values['device_info'];
1017 | }
1018 | /**
1019 | * 判断微信支付分配的终端设备号,与下单一致是否存在
1020 | * @return true 或 false
1021 | **/
1022 | public function IsDevice_infoSet()
1023 | {
1024 | return array_key_exists('device_info', $this->values);
1025 | }
1026 | /**
1027 | * 设置随机字符串,不长于32位。推荐随机数生成算法
1028 | * @param string $value
1029 | **/
1030 | public function SetNonce_str($value)
1031 | {
1032 | $this->values['nonce_str'] = $value;
1033 | }
1034 | /**
1035 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值
1036 | * @return 值
1037 | **/
1038 | public function GetNonce_str()
1039 | {
1040 | return $this->values['nonce_str'];
1041 | }
1042 | /**
1043 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
1044 | * @return true 或 false
1045 | **/
1046 | public function IsNonce_strSet()
1047 | {
1048 | return array_key_exists('nonce_str', $this->values);
1049 | }
1050 | /**
1051 | * 设置微信订单号
1052 | * @param string $value
1053 | **/
1054 | public function SetTransaction_id($value)
1055 | {
1056 | $this->values['transaction_id'] = $value;
1057 | }
1058 | /**
1059 | * 获取微信订单号的值
1060 | * @return 值
1061 | **/
1062 | public function GetTransaction_id()
1063 | {
1064 | return $this->values['transaction_id'];
1065 | }
1066 | /**
1067 | * 判断微信订单号是否存在
1068 | * @return true 或 false
1069 | **/
1070 | public function IsTransaction_idSet()
1071 | {
1072 | return array_key_exists('transaction_id', $this->values);
1073 | }
1074 | /**
1075 | * 设置商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no
1076 | * @param string $value
1077 | **/
1078 | public function SetOut_trade_no($value)
1079 | {
1080 | $this->values['out_trade_no'] = $value;
1081 | }
1082 | /**
1083 | * 获取商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no的值
1084 | * @return 值
1085 | **/
1086 | public function GetOut_trade_no()
1087 | {
1088 | return $this->values['out_trade_no'];
1089 | }
1090 | /**
1091 | * 判断商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no是否存在
1092 | * @return true 或 false
1093 | **/
1094 | public function IsOut_trade_noSet()
1095 | {
1096 | return array_key_exists('out_trade_no', $this->values);
1097 | }
1098 | /**
1099 | * 设置商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔
1100 | * @param string $value
1101 | **/
1102 | public function SetOut_refund_no($value)
1103 | {
1104 | $this->values['out_refund_no'] = $value;
1105 | }
1106 | /**
1107 | * 获取商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔的值
1108 | * @return 值
1109 | **/
1110 | public function GetOut_refund_no()
1111 | {
1112 | return $this->values['out_refund_no'];
1113 | }
1114 | /**
1115 | * 判断商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔是否存在
1116 | * @return true 或 false
1117 | **/
1118 | public function IsOut_refund_noSet()
1119 | {
1120 | return array_key_exists('out_refund_no', $this->values);
1121 | }
1122 | /**
1123 | * 设置订单总金额,单位为分,只能为整数,详见支付金额
1124 | * @param string $value
1125 | **/
1126 | public function SetTotal_fee($value)
1127 | {
1128 | $this->values['total_fee'] = $value;
1129 | }
1130 | /**
1131 | * 获取订单总金额,单位为分,只能为整数,详见支付金额的值
1132 | * @return 值
1133 | **/
1134 | public function GetTotal_fee()
1135 | {
1136 | return $this->values['total_fee'];
1137 | }
1138 | /**
1139 | * 判断订单总金额,单位为分,只能为整数,详见支付金额是否存在
1140 | * @return true 或 false
1141 | **/
1142 | public function IsTotal_feeSet()
1143 | {
1144 | return array_key_exists('total_fee', $this->values);
1145 | }
1146 | /**
1147 | * 设置退款总金额,订单总金额,单位为分,只能为整数,详见支付金额
1148 | * @param string $value
1149 | **/
1150 | public function SetRefund_fee($value)
1151 | {
1152 | $this->values['refund_fee'] = $value;
1153 | }
1154 | /**
1155 | * 获取退款总金额,订单总金额,单位为分,只能为整数,详见支付金额的值
1156 | * @return 值
1157 | **/
1158 | public function GetRefund_fee()
1159 | {
1160 | return $this->values['refund_fee'];
1161 | }
1162 | /**
1163 | * 判断退款总金额,订单总金额,单位为分,只能为整数,详见支付金额是否存在
1164 | * @return true 或 false
1165 | **/
1166 | public function IsRefund_feeSet()
1167 | {
1168 | return array_key_exists('refund_fee', $this->values);
1169 | }
1170 | /**
1171 | * 设置货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
1172 | * @param string $value
1173 | **/
1174 | public function SetRefund_fee_type($value)
1175 | {
1176 | $this->values['refund_fee_type'] = $value;
1177 | }
1178 | /**
1179 | * 获取货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型的值
1180 | * @return 值
1181 | **/
1182 | public function GetRefund_fee_type()
1183 | {
1184 | return $this->values['refund_fee_type'];
1185 | }
1186 | /**
1187 | * 判断货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型是否存在
1188 | * @return true 或 false
1189 | **/
1190 | public function IsRefund_fee_typeSet()
1191 | {
1192 | return array_key_exists('refund_fee_type', $this->values);
1193 | }
1194 | /**
1195 | * 设置操作员帐号, 默认为商户号
1196 | * @param string $value
1197 | **/
1198 | public function SetOp_user_id($value)
1199 | {
1200 | $this->values['op_user_id'] = $value;
1201 | }
1202 | /**
1203 | * 获取操作员帐号, 默认为商户号的值
1204 | * @return 值
1205 | **/
1206 | public function GetOp_user_id()
1207 | {
1208 | return $this->values['op_user_id'];
1209 | }
1210 | /**
1211 | * 判断操作员帐号, 默认为商户号是否存在
1212 | * @return true 或 false
1213 | **/
1214 | public function IsOp_user_idSet()
1215 | {
1216 | return array_key_exists('op_user_id', $this->values);
1217 | }
1218 | }
1219 | /**
1220 | *
1221 | * 退款查询输入对象
1222 | * @author widyhu
1223 | *
1224 | */
1225 | class WxPayRefundQuery extends WxPayDataBase
1226 | {
1227 | /**
1228 | * 设置微信分配的公众账号ID
1229 | * @param string $value
1230 | **/
1231 | public function SetAppid($value)
1232 | {
1233 | $this->values['appid'] = $value;
1234 | }
1235 | /**
1236 | * 获取微信分配的公众账号ID的值
1237 | * @return 值
1238 | **/
1239 | public function GetAppid()
1240 | {
1241 | return $this->values['appid'];
1242 | }
1243 | /**
1244 | * 判断微信分配的公众账号ID是否存在
1245 | * @return true 或 false
1246 | **/
1247 | public function IsAppidSet()
1248 | {
1249 | return array_key_exists('appid', $this->values);
1250 | }
1251 | /**
1252 | * 设置微信支付分配的商户号
1253 | * @param string $value
1254 | **/
1255 | public function SetMch_id($value)
1256 | {
1257 | $this->values['mch_id'] = $value;
1258 | }
1259 | /**
1260 | * 获取微信支付分配的商户号的值
1261 | * @return 值
1262 | **/
1263 | public function GetMch_id()
1264 | {
1265 | return $this->values['mch_id'];
1266 | }
1267 | /**
1268 | * 判断微信支付分配的商户号是否存在
1269 | * @return true 或 false
1270 | **/
1271 | public function IsMch_idSet()
1272 | {
1273 | return array_key_exists('mch_id', $this->values);
1274 | }
1275 | /**
1276 | * 设置微信支付分配的终端设备号
1277 | * @param string $value
1278 | **/
1279 | public function SetDevice_info($value)
1280 | {
1281 | $this->values['device_info'] = $value;
1282 | }
1283 | /**
1284 | * 获取微信支付分配的终端设备号的值
1285 | * @return 值
1286 | **/
1287 | public function GetDevice_info()
1288 | {
1289 | return $this->values['device_info'];
1290 | }
1291 | /**
1292 | * 判断微信支付分配的终端设备号是否存在
1293 | * @return true 或 false
1294 | **/
1295 | public function IsDevice_infoSet()
1296 | {
1297 | return array_key_exists('device_info', $this->values);
1298 | }
1299 | /**
1300 | * 设置随机字符串,不长于32位。推荐随机数生成算法
1301 | * @param string $value
1302 | **/
1303 | public function SetNonce_str($value)
1304 | {
1305 | $this->values['nonce_str'] = $value;
1306 | }
1307 | /**
1308 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值
1309 | * @return 值
1310 | **/
1311 | public function GetNonce_str()
1312 | {
1313 | return $this->values['nonce_str'];
1314 | }
1315 | /**
1316 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
1317 | * @return true 或 false
1318 | **/
1319 | public function IsNonce_strSet()
1320 | {
1321 | return array_key_exists('nonce_str', $this->values);
1322 | }
1323 | /**
1324 | * 设置微信订单号
1325 | * @param string $value
1326 | **/
1327 | public function SetTransaction_id($value)
1328 | {
1329 | $this->values['transaction_id'] = $value;
1330 | }
1331 | /**
1332 | * 获取微信订单号的值
1333 | * @return 值
1334 | **/
1335 | public function GetTransaction_id()
1336 | {
1337 | return $this->values['transaction_id'];
1338 | }
1339 | /**
1340 | * 判断微信订单号是否存在
1341 | * @return true 或 false
1342 | **/
1343 | public function IsTransaction_idSet()
1344 | {
1345 | return array_key_exists('transaction_id', $this->values);
1346 | }
1347 | /**
1348 | * 设置商户系统内部的订单号
1349 | * @param string $value
1350 | **/
1351 | public function SetOut_trade_no($value)
1352 | {
1353 | $this->values['out_trade_no'] = $value;
1354 | }
1355 | /**
1356 | * 获取商户系统内部的订单号的值
1357 | * @return 值
1358 | **/
1359 | public function GetOut_trade_no()
1360 | {
1361 | return $this->values['out_trade_no'];
1362 | }
1363 | /**
1364 | * 判断商户系统内部的订单号是否存在
1365 | * @return true 或 false
1366 | **/
1367 | public function IsOut_trade_noSet()
1368 | {
1369 | return array_key_exists('out_trade_no', $this->values);
1370 | }
1371 | /**
1372 | * 设置商户退款单号
1373 | * @param string $value
1374 | **/
1375 | public function SetOut_refund_no($value)
1376 | {
1377 | $this->values['out_refund_no'] = $value;
1378 | }
1379 | /**
1380 | * 获取商户退款单号的值
1381 | * @return 值
1382 | **/
1383 | public function GetOut_refund_no()
1384 | {
1385 | return $this->values['out_refund_no'];
1386 | }
1387 | /**
1388 | * 判断商户退款单号是否存在
1389 | * @return true 或 false
1390 | **/
1391 | public function IsOut_refund_noSet()
1392 | {
1393 | return array_key_exists('out_refund_no', $this->values);
1394 | }
1395 | /**
1396 | * 设置微信退款单号refund_id、out_refund_no、out_trade_no、transaction_id四个参数必填一个,如果同时存在优先级为:refund_id>out_refund_no>transaction_id>out_trade_no
1397 | * @param string $value
1398 | **/
1399 | public function SetRefund_id($value)
1400 | {
1401 | $this->values['refund_id'] = $value;
1402 | }
1403 | /**
1404 | * 获取微信退款单号refund_id、out_refund_no、out_trade_no、transaction_id四个参数必填一个,如果同时存在优先级为:refund_id>out_refund_no>transaction_id>out_trade_no的值
1405 | * @return 值
1406 | **/
1407 | public function GetRefund_id()
1408 | {
1409 | return $this->values['refund_id'];
1410 | }
1411 | /**
1412 | * 判断微信退款单号refund_id、out_refund_no、out_trade_no、transaction_id四个参数必填一个,如果同时存在优先级为:refund_id>out_refund_no>transaction_id>out_trade_no是否存在
1413 | * @return true 或 false
1414 | **/
1415 | public function IsRefund_idSet()
1416 | {
1417 | return array_key_exists('refund_id', $this->values);
1418 | }
1419 | }
1420 | /**
1421 | *
1422 | * 下载对账单输入对象
1423 | * @author widyhu
1424 | *
1425 | */
1426 | class WxPayDownloadBill extends WxPayDataBase
1427 | {
1428 | /**
1429 | * 设置微信分配的公众账号ID
1430 | * @param string $value
1431 | **/
1432 | public function SetAppid($value)
1433 | {
1434 | $this->values['appid'] = $value;
1435 | }
1436 | /**
1437 | * 获取微信分配的公众账号ID的值
1438 | * @return 值
1439 | **/
1440 | public function GetAppid()
1441 | {
1442 | return $this->values['appid'];
1443 | }
1444 | /**
1445 | * 判断微信分配的公众账号ID是否存在
1446 | * @return true 或 false
1447 | **/
1448 | public function IsAppidSet()
1449 | {
1450 | return array_key_exists('appid', $this->values);
1451 | }
1452 | /**
1453 | * 设置微信支付分配的商户号
1454 | * @param string $value
1455 | **/
1456 | public function SetMch_id($value)
1457 | {
1458 | $this->values['mch_id'] = $value;
1459 | }
1460 | /**
1461 | * 获取微信支付分配的商户号的值
1462 | * @return 值
1463 | **/
1464 | public function GetMch_id()
1465 | {
1466 | return $this->values['mch_id'];
1467 | }
1468 | /**
1469 | * 判断微信支付分配的商户号是否存在
1470 | * @return true 或 false
1471 | **/
1472 | public function IsMch_idSet()
1473 | {
1474 | return array_key_exists('mch_id', $this->values);
1475 | }
1476 | /**
1477 | * 设置微信支付分配的终端设备号,填写此字段,只下载该设备号的对账单
1478 | * @param string $value
1479 | **/
1480 | public function SetDevice_info($value)
1481 | {
1482 | $this->values['device_info'] = $value;
1483 | }
1484 | /**
1485 | * 获取微信支付分配的终端设备号,填写此字段,只下载该设备号的对账单的值
1486 | * @return 值
1487 | **/
1488 | public function GetDevice_info()
1489 | {
1490 | return $this->values['device_info'];
1491 | }
1492 | /**
1493 | * 判断微信支付分配的终端设备号,填写此字段,只下载该设备号的对账单是否存在
1494 | * @return true 或 false
1495 | **/
1496 | public function IsDevice_infoSet()
1497 | {
1498 | return array_key_exists('device_info', $this->values);
1499 | }
1500 | /**
1501 | * 设置随机字符串,不长于32位。推荐随机数生成算法
1502 | * @param string $value
1503 | **/
1504 | public function SetNonce_str($value)
1505 | {
1506 | $this->values['nonce_str'] = $value;
1507 | }
1508 | /**
1509 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值
1510 | * @return 值
1511 | **/
1512 | public function GetNonce_str()
1513 | {
1514 | return $this->values['nonce_str'];
1515 | }
1516 | /**
1517 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
1518 | * @return true 或 false
1519 | **/
1520 | public function IsNonce_strSet()
1521 | {
1522 | return array_key_exists('nonce_str', $this->values);
1523 | }
1524 | /**
1525 | * 设置下载对账单的日期,格式:20140603
1526 | * @param string $value
1527 | **/
1528 | public function SetBill_date($value)
1529 | {
1530 | $this->values['bill_date'] = $value;
1531 | }
1532 | /**
1533 | * 获取下载对账单的日期,格式:20140603的值
1534 | * @return 值
1535 | **/
1536 | public function GetBill_date()
1537 | {
1538 | return $this->values['bill_date'];
1539 | }
1540 | /**
1541 | * 判断下载对账单的日期,格式:20140603是否存在
1542 | * @return true 或 false
1543 | **/
1544 | public function IsBill_dateSet()
1545 | {
1546 | return array_key_exists('bill_date', $this->values);
1547 | }
1548 | /**
1549 | * 设置ALL,返回当日所有订单信息,默认值SUCCESS,返回当日成功支付的订单REFUND,返回当日退款订单REVOKED,已撤销的订单
1550 | * @param string $value
1551 | **/
1552 | public function SetBill_type($value)
1553 | {
1554 | $this->values['bill_type'] = $value;
1555 | }
1556 | /**
1557 | * 获取ALL,返回当日所有订单信息,默认值SUCCESS,返回当日成功支付的订单REFUND,返回当日退款订单REVOKED,已撤销的订单的值
1558 | * @return 值
1559 | **/
1560 | public function GetBill_type()
1561 | {
1562 | return $this->values['bill_type'];
1563 | }
1564 | /**
1565 | * 判断ALL,返回当日所有订单信息,默认值SUCCESS,返回当日成功支付的订单REFUND,返回当日退款订单REVOKED,已撤销的订单是否存在
1566 | * @return true 或 false
1567 | **/
1568 | public function IsBill_typeSet()
1569 | {
1570 | return array_key_exists('bill_type', $this->values);
1571 | }
1572 | }
1573 | /**
1574 | *
1575 | * 测速上报输入对象
1576 | * @author widyhu
1577 | *
1578 | */
1579 | class WxPayReport extends WxPayDataBase
1580 | {
1581 | /**
1582 | * 设置微信分配的公众账号ID
1583 | * @param string $value
1584 | **/
1585 | public function SetAppid($value)
1586 | {
1587 | $this->values['appid'] = $value;
1588 | }
1589 | /**
1590 | * 获取微信分配的公众账号ID的值
1591 | * @return 值
1592 | **/
1593 | public function GetAppid()
1594 | {
1595 | return $this->values['appid'];
1596 | }
1597 | /**
1598 | * 判断微信分配的公众账号ID是否存在
1599 | * @return true 或 false
1600 | **/
1601 | public function IsAppidSet()
1602 | {
1603 | return array_key_exists('appid', $this->values);
1604 | }
1605 | /**
1606 | * 设置微信支付分配的商户号
1607 | * @param string $value
1608 | **/
1609 | public function SetMch_id($value)
1610 | {
1611 | $this->values['mch_id'] = $value;
1612 | }
1613 | /**
1614 | * 获取微信支付分配的商户号的值
1615 | * @return 值
1616 | **/
1617 | public function GetMch_id()
1618 | {
1619 | return $this->values['mch_id'];
1620 | }
1621 | /**
1622 | * 判断微信支付分配的商户号是否存在
1623 | * @return true 或 false
1624 | **/
1625 | public function IsMch_idSet()
1626 | {
1627 | return array_key_exists('mch_id', $this->values);
1628 | }
1629 | /**
1630 | * 设置微信支付分配的终端设备号,商户自定义
1631 | * @param string $value
1632 | **/
1633 | public function SetDevice_info($value)
1634 | {
1635 | $this->values['device_info'] = $value;
1636 | }
1637 | /**
1638 | * 获取微信支付分配的终端设备号,商户自定义的值
1639 | * @return 值
1640 | **/
1641 | public function GetDevice_info()
1642 | {
1643 | return $this->values['device_info'];
1644 | }
1645 | /**
1646 | * 判断微信支付分配的终端设备号,商户自定义是否存在
1647 | * @return true 或 false
1648 | **/
1649 | public function IsDevice_infoSet()
1650 | {
1651 | return array_key_exists('device_info', $this->values);
1652 | }
1653 | /**
1654 | * 设置随机字符串,不长于32位。推荐随机数生成算法
1655 | * @param string $value
1656 | **/
1657 | public function SetNonce_str($value)
1658 | {
1659 | $this->values['nonce_str'] = $value;
1660 | }
1661 | /**
1662 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值
1663 | * @return 值
1664 | **/
1665 | public function GetNonce_str()
1666 | {
1667 | return $this->values['nonce_str'];
1668 | }
1669 | /**
1670 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
1671 | * @return true 或 false
1672 | **/
1673 | public function IsNonce_strSet()
1674 | {
1675 | return array_key_exists('nonce_str', $this->values);
1676 | }
1677 | /**
1678 | * 设置上报对应的接口的完整URL,类似:https://api.mch.weixin.qq.com/pay/unifiedorder对于被扫支付,为更好的和商户共同分析一次业务行为的整体耗时情况,对于两种接入模式,请都在门店侧对一次被扫行为进行一次单独的整体上报,上报URL指定为:https://api.mch.weixin.qq.com/pay/micropay/total关于两种接入模式具体可参考本文档章节:被扫支付商户接入模式其它接口调用仍然按照调用一次,上报一次来进行。
1679 | * @param string $value
1680 | **/
1681 | public function SetInterface_url($value)
1682 | {
1683 | $this->values['interface_url'] = $value;
1684 | }
1685 | /**
1686 | * 获取上报对应的接口的完整URL,类似:https://api.mch.weixin.qq.com/pay/unifiedorder对于被扫支付,为更好的和商户共同分析一次业务行为的整体耗时情况,对于两种接入模式,请都在门店侧对一次被扫行为进行一次单独的整体上报,上报URL指定为:https://api.mch.weixin.qq.com/pay/micropay/total关于两种接入模式具体可参考本文档章节:被扫支付商户接入模式其它接口调用仍然按照调用一次,上报一次来进行。的值
1687 | * @return 值
1688 | **/
1689 | public function GetInterface_url()
1690 | {
1691 | return $this->values['interface_url'];
1692 | }
1693 | /**
1694 | * 判断上报对应的接口的完整URL,类似:https://api.mch.weixin.qq.com/pay/unifiedorder对于被扫支付,为更好的和商户共同分析一次业务行为的整体耗时情况,对于两种接入模式,请都在门店侧对一次被扫行为进行一次单独的整体上报,上报URL指定为:https://api.mch.weixin.qq.com/pay/micropay/total关于两种接入模式具体可参考本文档章节:被扫支付商户接入模式其它接口调用仍然按照调用一次,上报一次来进行。是否存在
1695 | * @return true 或 false
1696 | **/
1697 | public function IsInterface_urlSet()
1698 | {
1699 | return array_key_exists('interface_url', $this->values);
1700 | }
1701 | /**
1702 | * 设置接口耗时情况,单位为毫秒
1703 | * @param string $value
1704 | **/
1705 | public function SetExecute_time_($value)
1706 | {
1707 | $this->values['execute_time_'] = $value;
1708 | }
1709 | /**
1710 | * 获取接口耗时情况,单位为毫秒的值
1711 | * @return 值
1712 | **/
1713 | public function GetExecute_time_()
1714 | {
1715 | return $this->values['execute_time_'];
1716 | }
1717 | /**
1718 | * 判断接口耗时情况,单位为毫秒是否存在
1719 | * @return true 或 false
1720 | **/
1721 | public function IsExecute_time_Set()
1722 | {
1723 | return array_key_exists('execute_time_', $this->values);
1724 | }
1725 | /**
1726 | * 设置SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断
1727 | * @param string $value
1728 | **/
1729 | public function SetReturn_code($value)
1730 | {
1731 | $this->values['return_code'] = $value;
1732 | }
1733 | /**
1734 | * 获取SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断的值
1735 | * @return 值
1736 | **/
1737 | public function GetReturn_code()
1738 | {
1739 | return $this->values['return_code'];
1740 | }
1741 | /**
1742 | * 判断SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查看trade_state来判断是否存在
1743 | * @return true 或 false
1744 | **/
1745 | public function IsReturn_codeSet()
1746 | {
1747 | return array_key_exists('return_code', $this->values);
1748 | }
1749 | /**
1750 | * 设置返回信息,如非空,为错误原因签名失败参数格式校验错误
1751 | * @param string $value
1752 | **/
1753 | public function SetReturn_msg($value)
1754 | {
1755 | $this->values['return_msg'] = $value;
1756 | }
1757 | /**
1758 | * 获取返回信息,如非空,为错误原因签名失败参数格式校验错误的值
1759 | * @return 值
1760 | **/
1761 | public function GetReturn_msg()
1762 | {
1763 | return $this->values['return_msg'];
1764 | }
1765 | /**
1766 | * 判断返回信息,如非空,为错误原因签名失败参数格式校验错误是否存在
1767 | * @return true 或 false
1768 | **/
1769 | public function IsReturn_msgSet()
1770 | {
1771 | return array_key_exists('return_msg', $this->values);
1772 | }
1773 | /**
1774 | * 设置SUCCESS/FAIL
1775 | * @param string $value
1776 | **/
1777 | public function SetResult_code($value)
1778 | {
1779 | $this->values['result_code'] = $value;
1780 | }
1781 | /**
1782 | * 获取SUCCESS/FAIL的值
1783 | * @return 值
1784 | **/
1785 | public function GetResult_code()
1786 | {
1787 | return $this->values['result_code'];
1788 | }
1789 | /**
1790 | * 判断SUCCESS/FAIL是否存在
1791 | * @return true 或 false
1792 | **/
1793 | public function IsResult_codeSet()
1794 | {
1795 | return array_key_exists('result_code', $this->values);
1796 | }
1797 | /**
1798 | * 设置ORDERNOTEXIST—订单不存在SYSTEMERROR—系统错误
1799 | * @param string $value
1800 | **/
1801 | public function SetErr_code($value)
1802 | {
1803 | $this->values['err_code'] = $value;
1804 | }
1805 | /**
1806 | * 获取ORDERNOTEXIST—订单不存在SYSTEMERROR—系统错误的值
1807 | * @return 值
1808 | **/
1809 | public function GetErr_code()
1810 | {
1811 | return $this->values['err_code'];
1812 | }
1813 | /**
1814 | * 判断ORDERNOTEXIST—订单不存在SYSTEMERROR—系统错误是否存在
1815 | * @return true 或 false
1816 | **/
1817 | public function IsErr_codeSet()
1818 | {
1819 | return array_key_exists('err_code', $this->values);
1820 | }
1821 | /**
1822 | * 设置结果信息描述
1823 | * @param string $value
1824 | **/
1825 | public function SetErr_code_des($value)
1826 | {
1827 | $this->values['err_code_des'] = $value;
1828 | }
1829 | /**
1830 | * 获取结果信息描述的值
1831 | * @return 值
1832 | **/
1833 | public function GetErr_code_des()
1834 | {
1835 | return $this->values['err_code_des'];
1836 | }
1837 | /**
1838 | * 判断结果信息描述是否存在
1839 | * @return true 或 false
1840 | **/
1841 | public function IsErr_code_desSet()
1842 | {
1843 | return array_key_exists('err_code_des', $this->values);
1844 | }
1845 | /**
1846 | * 设置商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。
1847 | * @param string $value
1848 | **/
1849 | public function SetOut_trade_no($value)
1850 | {
1851 | $this->values['out_trade_no'] = $value;
1852 | }
1853 | /**
1854 | * 获取商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。 的值
1855 | * @return 值
1856 | **/
1857 | public function GetOut_trade_no()
1858 | {
1859 | return $this->values['out_trade_no'];
1860 | }
1861 | /**
1862 | * 判断商户系统内部的订单号,商户可以在上报时提供相关商户订单号方便微信支付更好的提高服务质量。 是否存在
1863 | * @return true 或 false
1864 | **/
1865 | public function IsOut_trade_noSet()
1866 | {
1867 | return array_key_exists('out_trade_no', $this->values);
1868 | }
1869 | /**
1870 | * 设置发起接口调用时的机器IP
1871 | * @param string $value
1872 | **/
1873 | public function SetUser_ip($value)
1874 | {
1875 | $this->values['user_ip'] = $value;
1876 | }
1877 | /**
1878 | * 获取发起接口调用时的机器IP 的值
1879 | * @return 值
1880 | **/
1881 | public function GetUser_ip()
1882 | {
1883 | return $this->values['user_ip'];
1884 | }
1885 | /**
1886 | * 判断发起接口调用时的机器IP 是否存在
1887 | * @return true 或 false
1888 | **/
1889 | public function IsUser_ipSet()
1890 | {
1891 | return array_key_exists('user_ip', $this->values);
1892 | }
1893 | /**
1894 | * 设置系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则
1895 | * @param string $value
1896 | **/
1897 | public function SetTime($value)
1898 | {
1899 | $this->values['time'] = $value;
1900 | }
1901 | /**
1902 | * 获取系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则的值
1903 | * @return 值
1904 | **/
1905 | public function GetTime()
1906 | {
1907 | return $this->values['time'];
1908 | }
1909 | /**
1910 | * 判断系统时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则是否存在
1911 | * @return true 或 false
1912 | **/
1913 | public function IsTimeSet()
1914 | {
1915 | return array_key_exists('time', $this->values);
1916 | }
1917 | }
1918 | /**
1919 | *
1920 | * 短链转换输入对象
1921 | * @author widyhu
1922 | *
1923 | */
1924 | class WxPayShortUrl extends WxPayDataBase
1925 | {
1926 | /**
1927 | * 设置微信分配的公众账号ID
1928 | * @param string $value
1929 | **/
1930 | public function SetAppid($value)
1931 | {
1932 | $this->values['appid'] = $value;
1933 | }
1934 | /**
1935 | * 获取微信分配的公众账号ID的值
1936 | * @return 值
1937 | **/
1938 | public function GetAppid()
1939 | {
1940 | return $this->values['appid'];
1941 | }
1942 | /**
1943 | * 判断微信分配的公众账号ID是否存在
1944 | * @return true 或 false
1945 | **/
1946 | public function IsAppidSet()
1947 | {
1948 | return array_key_exists('appid', $this->values);
1949 | }
1950 | /**
1951 | * 设置微信支付分配的商户号
1952 | * @param string $value
1953 | **/
1954 | public function SetMch_id($value)
1955 | {
1956 | $this->values['mch_id'] = $value;
1957 | }
1958 | /**
1959 | * 获取微信支付分配的商户号的值
1960 | * @return 值
1961 | **/
1962 | public function GetMch_id()
1963 | {
1964 | return $this->values['mch_id'];
1965 | }
1966 | /**
1967 | * 判断微信支付分配的商户号是否存在
1968 | * @return true 或 false
1969 | **/
1970 | public function IsMch_idSet()
1971 | {
1972 | return array_key_exists('mch_id', $this->values);
1973 | }
1974 | /**
1975 | * 设置需要转换的URL,签名用原串,传输需URL encode
1976 | * @param string $value
1977 | **/
1978 | public function SetLong_url($value)
1979 | {
1980 | $this->values['long_url'] = $value;
1981 | }
1982 | /**
1983 | * 获取需要转换的URL,签名用原串,传输需URL encode的值
1984 | * @return 值
1985 | **/
1986 | public function GetLong_url()
1987 | {
1988 | return $this->values['long_url'];
1989 | }
1990 | /**
1991 | * 判断需要转换的URL,签名用原串,传输需URL encode是否存在
1992 | * @return true 或 false
1993 | **/
1994 | public function IsLong_urlSet()
1995 | {
1996 | return array_key_exists('long_url', $this->values);
1997 | }
1998 | /**
1999 | * 设置随机字符串,不长于32位。推荐随机数生成算法
2000 | * @param string $value
2001 | **/
2002 | public function SetNonce_str($value)
2003 | {
2004 | $this->values['nonce_str'] = $value;
2005 | }
2006 | /**
2007 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值
2008 | * @return 值
2009 | **/
2010 | public function GetNonce_str()
2011 | {
2012 | return $this->values['nonce_str'];
2013 | }
2014 | /**
2015 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
2016 | * @return true 或 false
2017 | **/
2018 | public function IsNonce_strSet()
2019 | {
2020 | return array_key_exists('nonce_str', $this->values);
2021 | }
2022 | }
2023 | /**
2024 | *
2025 | * 提交被扫输入对象
2026 | * @author widyhu
2027 | *
2028 | */
2029 | class WxPayMicroPay extends WxPayDataBase
2030 | {
2031 | /**
2032 | * 设置微信分配的公众账号ID
2033 | * @param string $value
2034 | **/
2035 | public function SetAppid($value)
2036 | {
2037 | $this->values['appid'] = $value;
2038 | }
2039 | /**
2040 | * 获取微信分配的公众账号ID的值
2041 | * @return 值
2042 | **/
2043 | public function GetAppid()
2044 | {
2045 | return $this->values['appid'];
2046 | }
2047 | /**
2048 | * 判断微信分配的公众账号ID是否存在
2049 | * @return true 或 false
2050 | **/
2051 | public function IsAppidSet()
2052 | {
2053 | return array_key_exists('appid', $this->values);
2054 | }
2055 | /**
2056 | * 设置微信支付分配的商户号
2057 | * @param string $value
2058 | **/
2059 | public function SetMch_id($value)
2060 | {
2061 | $this->values['mch_id'] = $value;
2062 | }
2063 | /**
2064 | * 获取微信支付分配的商户号的值
2065 | * @return 值
2066 | **/
2067 | public function GetMch_id()
2068 | {
2069 | return $this->values['mch_id'];
2070 | }
2071 | /**
2072 | * 判断微信支付分配的商户号是否存在
2073 | * @return true 或 false
2074 | **/
2075 | public function IsMch_idSet()
2076 | {
2077 | return array_key_exists('mch_id', $this->values);
2078 | }
2079 | /**
2080 | * 设置终端设备号(商户自定义,如门店编号)
2081 | * @param string $value
2082 | **/
2083 | public function SetDevice_info($value)
2084 | {
2085 | $this->values['device_info'] = $value;
2086 | }
2087 | /**
2088 | * 获取终端设备号(商户自定义,如门店编号)的值
2089 | * @return 值
2090 | **/
2091 | public function GetDevice_info()
2092 | {
2093 | return $this->values['device_info'];
2094 | }
2095 | /**
2096 | * 判断终端设备号(商户自定义,如门店编号)是否存在
2097 | * @return true 或 false
2098 | **/
2099 | public function IsDevice_infoSet()
2100 | {
2101 | return array_key_exists('device_info', $this->values);
2102 | }
2103 | /**
2104 | * 设置随机字符串,不长于32位。推荐随机数生成算法
2105 | * @param string $value
2106 | **/
2107 | public function SetNonce_str($value)
2108 | {
2109 | $this->values['nonce_str'] = $value;
2110 | }
2111 | /**
2112 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值
2113 | * @return 值
2114 | **/
2115 | public function GetNonce_str()
2116 | {
2117 | return $this->values['nonce_str'];
2118 | }
2119 | /**
2120 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
2121 | * @return true 或 false
2122 | **/
2123 | public function IsNonce_strSet()
2124 | {
2125 | return array_key_exists('nonce_str', $this->values);
2126 | }
2127 | /**
2128 | * 设置商品或支付单简要描述
2129 | * @param string $value
2130 | **/
2131 | public function SetBody($value)
2132 | {
2133 | $this->values['body'] = $value;
2134 | }
2135 | /**
2136 | * 获取商品或支付单简要描述的值
2137 | * @return 值
2138 | **/
2139 | public function GetBody()
2140 | {
2141 | return $this->values['body'];
2142 | }
2143 | /**
2144 | * 判断商品或支付单简要描述是否存在
2145 | * @return true 或 false
2146 | **/
2147 | public function IsBodySet()
2148 | {
2149 | return array_key_exists('body', $this->values);
2150 | }
2151 | /**
2152 | * 设置商品名称明细列表
2153 | * @param string $value
2154 | **/
2155 | public function SetDetail($value)
2156 | {
2157 | $this->values['detail'] = $value;
2158 | }
2159 | /**
2160 | * 获取商品名称明细列表的值
2161 | * @return 值
2162 | **/
2163 | public function GetDetail()
2164 | {
2165 | return $this->values['detail'];
2166 | }
2167 | /**
2168 | * 判断商品名称明细列表是否存在
2169 | * @return true 或 false
2170 | **/
2171 | public function IsDetailSet()
2172 | {
2173 | return array_key_exists('detail', $this->values);
2174 | }
2175 | /**
2176 | * 设置附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
2177 | * @param string $value
2178 | **/
2179 | public function SetAttach($value)
2180 | {
2181 | $this->values['attach'] = $value;
2182 | }
2183 | /**
2184 | * 获取附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据的值
2185 | * @return 值
2186 | **/
2187 | public function GetAttach()
2188 | {
2189 | return $this->values['attach'];
2190 | }
2191 | /**
2192 | * 判断附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据是否存在
2193 | * @return true 或 false
2194 | **/
2195 | public function IsAttachSet()
2196 | {
2197 | return array_key_exists('attach', $this->values);
2198 | }
2199 | /**
2200 | * 设置商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
2201 | * @param string $value
2202 | **/
2203 | public function SetOut_trade_no($value)
2204 | {
2205 | $this->values['out_trade_no'] = $value;
2206 | }
2207 | /**
2208 | * 获取商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号的值
2209 | * @return 值
2210 | **/
2211 | public function GetOut_trade_no()
2212 | {
2213 | return $this->values['out_trade_no'];
2214 | }
2215 | /**
2216 | * 判断商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号是否存在
2217 | * @return true 或 false
2218 | **/
2219 | public function IsOut_trade_noSet()
2220 | {
2221 | return array_key_exists('out_trade_no', $this->values);
2222 | }
2223 | /**
2224 | * 设置订单总金额,单位为分,只能为整数,详见支付金额
2225 | * @param string $value
2226 | **/
2227 | public function SetTotal_fee($value)
2228 | {
2229 | $this->values['total_fee'] = $value;
2230 | }
2231 | /**
2232 | * 获取订单总金额,单位为分,只能为整数,详见支付金额的值
2233 | * @return 值
2234 | **/
2235 | public function GetTotal_fee()
2236 | {
2237 | return $this->values['total_fee'];
2238 | }
2239 | /**
2240 | * 判断订单总金额,单位为分,只能为整数,详见支付金额是否存在
2241 | * @return true 或 false
2242 | **/
2243 | public function IsTotal_feeSet()
2244 | {
2245 | return array_key_exists('total_fee', $this->values);
2246 | }
2247 | /**
2248 | * 设置符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
2249 | * @param string $value
2250 | **/
2251 | public function SetFee_type($value)
2252 | {
2253 | $this->values['fee_type'] = $value;
2254 | }
2255 | /**
2256 | * 获取符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型的值
2257 | * @return 值
2258 | **/
2259 | public function GetFee_type()
2260 | {
2261 | return $this->values['fee_type'];
2262 | }
2263 | /**
2264 | * 判断符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型是否存在
2265 | * @return true 或 false
2266 | **/
2267 | public function IsFee_typeSet()
2268 | {
2269 | return array_key_exists('fee_type', $this->values);
2270 | }
2271 | /**
2272 | * 设置调用微信支付API的机器IP
2273 | * @param string $value
2274 | **/
2275 | public function SetSpbill_create_ip($value)
2276 | {
2277 | $this->values['spbill_create_ip'] = $value;
2278 | }
2279 | /**
2280 | * 获取调用微信支付API的机器IP 的值
2281 | * @return 值
2282 | **/
2283 | public function GetSpbill_create_ip()
2284 | {
2285 | return $this->values['spbill_create_ip'];
2286 | }
2287 | /**
2288 | * 判断调用微信支付API的机器IP 是否存在
2289 | * @return true 或 false
2290 | **/
2291 | public function IsSpbill_create_ipSet()
2292 | {
2293 | return array_key_exists('spbill_create_ip', $this->values);
2294 | }
2295 | /**
2296 | * 设置订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。详见时间规则
2297 | * @param string $value
2298 | **/
2299 | public function SetTime_start($value)
2300 | {
2301 | $this->values['time_start'] = $value;
2302 | }
2303 | /**
2304 | * 获取订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。详见时间规则的值
2305 | * @return 值
2306 | **/
2307 | public function GetTime_start()
2308 | {
2309 | return $this->values['time_start'];
2310 | }
2311 | /**
2312 | * 判断订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。详见时间规则是否存在
2313 | * @return true 或 false
2314 | **/
2315 | public function IsTime_startSet()
2316 | {
2317 | return array_key_exists('time_start', $this->values);
2318 | }
2319 | /**
2320 | * 设置订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。详见时间规则
2321 | * @param string $value
2322 | **/
2323 | public function SetTime_expire($value)
2324 | {
2325 | $this->values['time_expire'] = $value;
2326 | }
2327 | /**
2328 | * 获取订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。详见时间规则的值
2329 | * @return 值
2330 | **/
2331 | public function GetTime_expire()
2332 | {
2333 | return $this->values['time_expire'];
2334 | }
2335 | /**
2336 | * 判断订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。详见时间规则是否存在
2337 | * @return true 或 false
2338 | **/
2339 | public function IsTime_expireSet()
2340 | {
2341 | return array_key_exists('time_expire', $this->values);
2342 | }
2343 | /**
2344 | * 设置商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠
2345 | * @param string $value
2346 | **/
2347 | public function SetGoods_tag($value)
2348 | {
2349 | $this->values['goods_tag'] = $value;
2350 | }
2351 | /**
2352 | * 获取商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠的值
2353 | * @return 值
2354 | **/
2355 | public function GetGoods_tag()
2356 | {
2357 | return $this->values['goods_tag'];
2358 | }
2359 | /**
2360 | * 判断商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠是否存在
2361 | * @return true 或 false
2362 | **/
2363 | public function IsGoods_tagSet()
2364 | {
2365 | return array_key_exists('goods_tag', $this->values);
2366 | }
2367 | /**
2368 | * 设置扫码支付授权码,设备读取用户微信中的条码或者二维码信息
2369 | * @param string $value
2370 | **/
2371 | public function SetAuth_code($value)
2372 | {
2373 | $this->values['auth_code'] = $value;
2374 | }
2375 | /**
2376 | * 获取扫码支付授权码,设备读取用户微信中的条码或者二维码信息的值
2377 | * @return 值
2378 | **/
2379 | public function GetAuth_code()
2380 | {
2381 | return $this->values['auth_code'];
2382 | }
2383 | /**
2384 | * 判断扫码支付授权码,设备读取用户微信中的条码或者二维码信息是否存在
2385 | * @return true 或 false
2386 | **/
2387 | public function IsAuth_codeSet()
2388 | {
2389 | return array_key_exists('auth_code', $this->values);
2390 | }
2391 | }
2392 | /**
2393 | *
2394 | * 撤销输入对象
2395 | * @author widyhu
2396 | *
2397 | */
2398 | class WxPayReverse extends WxPayDataBase
2399 | {
2400 | /**
2401 | * 设置微信分配的公众账号ID
2402 | * @param string $value
2403 | **/
2404 | public function SetAppid($value)
2405 | {
2406 | $this->values['appid'] = $value;
2407 | }
2408 | /**
2409 | * 获取微信分配的公众账号ID的值
2410 | * @return 值
2411 | **/
2412 | public function GetAppid()
2413 | {
2414 | return $this->values['appid'];
2415 | }
2416 | /**
2417 | * 判断微信分配的公众账号ID是否存在
2418 | * @return true 或 false
2419 | **/
2420 | public function IsAppidSet()
2421 | {
2422 | return array_key_exists('appid', $this->values);
2423 | }
2424 | /**
2425 | * 设置微信支付分配的商户号
2426 | * @param string $value
2427 | **/
2428 | public function SetMch_id($value)
2429 | {
2430 | $this->values['mch_id'] = $value;
2431 | }
2432 | /**
2433 | * 获取微信支付分配的商户号的值
2434 | * @return 值
2435 | **/
2436 | public function GetMch_id()
2437 | {
2438 | return $this->values['mch_id'];
2439 | }
2440 | /**
2441 | * 判断微信支付分配的商户号是否存在
2442 | * @return true 或 false
2443 | **/
2444 | public function IsMch_idSet()
2445 | {
2446 | return array_key_exists('mch_id', $this->values);
2447 | }
2448 | /**
2449 | * 设置微信的订单号,优先使用
2450 | * @param string $value
2451 | **/
2452 | public function SetTransaction_id($value)
2453 | {
2454 | $this->values['transaction_id'] = $value;
2455 | }
2456 | /**
2457 | * 获取微信的订单号,优先使用的值
2458 | * @return 值
2459 | **/
2460 | public function GetTransaction_id()
2461 | {
2462 | return $this->values['transaction_id'];
2463 | }
2464 | /**
2465 | * 判断微信的订单号,优先使用是否存在
2466 | * @return true 或 false
2467 | **/
2468 | public function IsTransaction_idSet()
2469 | {
2470 | return array_key_exists('transaction_id', $this->values);
2471 | }
2472 | /**
2473 | * 设置商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no
2474 | * @param string $value
2475 | **/
2476 | public function SetOut_trade_no($value)
2477 | {
2478 | $this->values['out_trade_no'] = $value;
2479 | }
2480 | /**
2481 | * 获取商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no的值
2482 | * @return 值
2483 | **/
2484 | public function GetOut_trade_no()
2485 | {
2486 | return $this->values['out_trade_no'];
2487 | }
2488 | /**
2489 | * 判断商户系统内部的订单号,transaction_id、out_trade_no二选一,如果同时存在优先级:transaction_id> out_trade_no是否存在
2490 | * @return true 或 false
2491 | **/
2492 | public function IsOut_trade_noSet()
2493 | {
2494 | return array_key_exists('out_trade_no', $this->values);
2495 | }
2496 | /**
2497 | * 设置随机字符串,不长于32位。推荐随机数生成算法
2498 | * @param string $value
2499 | **/
2500 | public function SetNonce_str($value)
2501 | {
2502 | $this->values['nonce_str'] = $value;
2503 | }
2504 | /**
2505 | * 获取随机字符串,不长于32位。推荐随机数生成算法的值
2506 | * @return 值
2507 | **/
2508 | public function GetNonce_str()
2509 | {
2510 | return $this->values['nonce_str'];
2511 | }
2512 | /**
2513 | * 判断随机字符串,不长于32位。推荐随机数生成算法是否存在
2514 | * @return true 或 false
2515 | **/
2516 | public function IsNonce_strSet()
2517 | {
2518 | return array_key_exists('nonce_str', $this->values);
2519 | }
2520 | }
2521 | /**
2522 | *
2523 | * 提交JSAPI输入对象
2524 | * @author widyhu
2525 | *
2526 | */
2527 | class WxPayJsApiPay extends WxPayDataBase
2528 | {
2529 | /**
2530 | * 设置微信分配的公众账号ID
2531 | * @param string $value
2532 | **/
2533 | public function SetAppid($value)
2534 | {
2535 | $this->values['appId'] = $value;
2536 | }
2537 | /**
2538 | * 获取微信分配的公众账号ID的值
2539 | * @return 值
2540 | **/
2541 | public function GetAppid()
2542 | {
2543 | return $this->values['appId'];
2544 | }
2545 | /**
2546 | * 判断微信分配的公众账号ID是否存在
2547 | * @return true 或 false
2548 | **/
2549 | public function IsAppidSet()
2550 | {
2551 | return array_key_exists('appId', $this->values);
2552 | }
2553 | /**
2554 | * 设置支付时间戳
2555 | * @param string $value
2556 | **/
2557 | public function SetTimeStamp($value)
2558 | {
2559 | $this->values['timeStamp'] = $value;
2560 | }
2561 | /**
2562 | * 获取支付时间戳的值
2563 | * @return 值
2564 | **/
2565 | public function GetTimeStamp()
2566 | {
2567 | return $this->values['timeStamp'];
2568 | }
2569 | /**
2570 | * 判断支付时间戳是否存在
2571 | * @return true 或 false
2572 | **/
2573 | public function IsTimeStampSet()
2574 | {
2575 | return array_key_exists('timeStamp', $this->values);
2576 | }
2577 |
2578 | /**
2579 | * 随机字符串
2580 | * @param string $value
2581 | **/
2582 | public function SetNonceStr($value)
2583 | {
2584 | $this->values['nonceStr'] = $value;
2585 | }
2586 | /**
2587 | * 获取notify随机字符串值
2588 | * @return 值
2589 | **/
2590 | public function GetReturn_code()
2591 | {
2592 | return $this->values['nonceStr'];
2593 | }
2594 | /**
2595 | * 判断随机字符串是否存在
2596 | * @return true 或 false
2597 | **/
2598 | public function IsReturn_codeSet()
2599 | {
2600 | return array_key_exists('nonceStr', $this->values);
2601 | }
2602 | /**
2603 | * 设置订单详情扩展字符串
2604 | * @param string $value
2605 | **/
2606 | public function SetPackage($value)
2607 | {
2608 | $this->values['package'] = $value;
2609 | }
2610 | /**
2611 | * 获取订单详情扩展字符串的值
2612 | * @return 值
2613 | **/
2614 | public function GetPackage()
2615 | {
2616 | return $this->values['package'];
2617 | }
2618 | /**
2619 | * 判断订单详情扩展字符串是否存在
2620 | * @return true 或 false
2621 | **/
2622 | public function IsPackageSet()
2623 | {
2624 | return array_key_exists('package', $this->values);
2625 | }
2626 |
2627 | /**
2628 | * 设置签名方式
2629 | * @param string $value
2630 | **/
2631 | public function SetSignType($value)
2632 | {
2633 | $this->values['signType'] = $value;
2634 | }
2635 | /**
2636 | * 获取签名方式
2637 | * @return 值
2638 | **/
2639 | public function GetSignType()
2640 | {
2641 | return $this->values['signType'];
2642 | }
2643 | /**
2644 | * 判断签名方式是否存在
2645 | * @return true 或 false
2646 | **/
2647 | public function IsSignTypeSet()
2648 | {
2649 | return array_key_exists('signType', $this->values);
2650 | }
2651 |
2652 | /**
2653 | * 设置签名方式
2654 | * @param string $value
2655 | **/
2656 | public function SetPaySign($value)
2657 | {
2658 | $this->values['paySign'] = $value;
2659 | }
2660 | /**
2661 | * 获取签名方式
2662 | * @return 值
2663 | **/
2664 | public function GetPaySign()
2665 | {
2666 | return $this->values['paySign'];
2667 | }
2668 | /**
2669 | * 判断签名方式是否存在
2670 | * @return true 或 false
2671 | **/
2672 | public function IsPaySignSet()
2673 | {
2674 | return array_key_exists('paySign', $this->values);
2675 | }
2676 | }
2677 | /**
2678 | *
2679 | * 扫码支付模式一生成二维码参数
2680 | * @author widyhu
2681 | *
2682 | */
2683 | class WxPayBizPayUrl extends WxPayDataBase
2684 | {
2685 | /**
2686 | * 设置微信分配的公众账号ID
2687 | * @param string $value
2688 | **/
2689 | public function SetAppid($value)
2690 | {
2691 | $this->values['appid'] = $value;
2692 | }
2693 | /**
2694 | * 获取微信分配的公众账号ID的值
2695 | * @return 值
2696 | **/
2697 | public function GetAppid()
2698 | {
2699 | return $this->values['appid'];
2700 | }
2701 | /**
2702 | * 判断微信分配的公众账号ID是否存在
2703 | * @return true 或 false
2704 | **/
2705 | public function IsAppidSet()
2706 | {
2707 | return array_key_exists('appid', $this->values);
2708 | }
2709 | /**
2710 | * 设置微信支付分配的商户号
2711 | * @param string $value
2712 | **/
2713 | public function SetMch_id($value)
2714 | {
2715 | $this->values['mch_id'] = $value;
2716 | }
2717 | /**
2718 | * 获取微信支付分配的商户号的值
2719 | * @return 值
2720 | **/
2721 | public function GetMch_id()
2722 | {
2723 | return $this->values['mch_id'];
2724 | }
2725 | /**
2726 | * 判断微信支付分配的商户号是否存在
2727 | * @return true 或 false
2728 | **/
2729 | public function IsMch_idSet()
2730 | {
2731 | return array_key_exists('mch_id', $this->values);
2732 | }
2733 |
2734 | /**
2735 | * 设置支付时间戳
2736 | * @param string $value
2737 | **/
2738 | public function SetTime_stamp($value)
2739 | {
2740 | $this->values['time_stamp'] = $value;
2741 | }
2742 | /**
2743 | * 获取支付时间戳的值
2744 | * @return 值
2745 | **/
2746 | public function GetTime_stamp()
2747 | {
2748 | return $this->values['time_stamp'];
2749 | }
2750 | /**
2751 | * 判断支付时间戳是否存在
2752 | * @return true 或 false
2753 | **/
2754 | public function IsTime_stampSet()
2755 | {
2756 | return array_key_exists('time_stamp', $this->values);
2757 | }
2758 |
2759 | /**
2760 | * 设置随机字符串
2761 | * @param string $value
2762 | **/
2763 | public function SetNonce_str($value)
2764 | {
2765 | $this->values['nonce_str'] = $value;
2766 | }
2767 | /**
2768 | * 获取随机字符串的值
2769 | * @return 值
2770 | **/
2771 | public function GetNonce_str()
2772 | {
2773 | return $this->values['nonce_str'];
2774 | }
2775 | /**
2776 | * 判断随机字符串是否存在
2777 | * @return true 或 false
2778 | **/
2779 | public function IsNonce_strSet()
2780 | {
2781 | return array_key_exists('nonce_str', $this->values);
2782 | }
2783 |
2784 | /**
2785 | * 设置商品ID
2786 | * @param string $value
2787 | **/
2788 | public function SetProduct_id($value)
2789 | {
2790 | $this->values['product_id'] = $value;
2791 | }
2792 | /**
2793 | * 获取商品ID的值
2794 | * @return 值
2795 | **/
2796 | public function GetProduct_id()
2797 | {
2798 | return $this->values['product_id'];
2799 | }
2800 | /**
2801 | * 判断商品ID是否存在
2802 | * @return true 或 false
2803 | **/
2804 | public function IsProduct_idSet()
2805 | {
2806 | return array_key_exists('product_id', $this->values);
2807 | }
2808 | }
--------------------------------------------------------------------------------
/weixinJSAPIpay/WxPay.Exception.php:
--------------------------------------------------------------------------------
1 | getMessage();
12 | }
13 | }
--------------------------------------------------------------------------------
/weixinJSAPIpay/WxPay.JsApiPay.php:
--------------------------------------------------------------------------------
1 | __CreateOauthUrlForCode($baseUrl);
52 | //echo $url;die;
53 | $this->writelog($url);
54 | echo 9897;die;
55 | Header("Location: $url");
56 | exit();
57 | } else {
58 | //获取code码,以获取openid
59 | $code = $_GET['code'];
60 | $openid = $this->getOpenidFromMp($code);
61 | WeixinJSBridge.log($openid);
62 | return $openid;
63 | }
64 | }
65 |
66 | /**
67 | *
68 | * 获取jsapi支付的参数
69 | * @param array $UnifiedOrderResult 统一支付接口返回的数据
70 | * @throws WxPayException
71 | *
72 | * @return json数据,可直接填入js函数作为参数
73 | */
74 | public function GetJsApiParameters($UnifiedOrderResult)
75 | {
76 | if(!array_key_exists("appid", $UnifiedOrderResult)
77 | || !array_key_exists("prepay_id", $UnifiedOrderResult)
78 | || $UnifiedOrderResult['prepay_id'] == "")
79 | {
80 | throw new WxPayException("参数错误");
81 | }
82 | $jsapi = new WxPayJsApiPay();
83 | $jsapi->SetAppid($UnifiedOrderResult["appid"]);
84 | $timeStamp = time();
85 | $jsapi->SetTimeStamp("$timeStamp");
86 | $jsapi->SetNonceStr(WxPayApi::getNonceStr());
87 | $jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']);
88 | $jsapi->SetSignType("MD5");
89 | $jsapi->SetPaySign($jsapi->MakeSign());
90 | $parameters = json_encode($jsapi->GetValues());
91 | return $parameters;
92 | }
93 | //rizhi
94 | function writelog($message)
95 | {
96 | $logFileDir = './';
97 | $logFile = 'monitor' . date('Y-m-d') . '.txt';
98 |
99 | $log = date('Y-m-d H:i:s') . ' - ' . $message . "\n";
100 |
101 | $fp = fopen($logFileDir.$logFile, 'a+');
102 |
103 | fwrite($fp, $log);
104 | fclose($fp);
105 | }
106 | /**
107 | *
108 | * 通过code从工作平台获取openid机器access_token
109 | * @param string $code 微信跳转回来带上的code
110 | *
111 | * @return openid
112 | */
113 | public function GetOpenidFromMp($code)
114 | {
115 | $url = $this->__CreateOauthUrlForOpenid($code);
116 | //初始化curl
117 | $ch = curl_init();
118 | //设置超时
119 | curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_timeout);
120 | curl_setopt($ch, CURLOPT_URL, $url);
121 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
122 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
123 | curl_setopt($ch, CURLOPT_HEADER, FALSE);
124 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
125 | if(WxPayConfig::CURL_PROXY_HOST != "0.0.0.0"
126 | && WxPayConfig::CURL_PROXY_PORT != 0){
127 | curl_setopt($ch,CURLOPT_PROXY, WxPayConfig::CURL_PROXY_HOST);
128 | curl_setopt($ch,CURLOPT_PROXYPORT, WxPayConfig::CURL_PROXY_PORT);
129 | }
130 | //运行curl,结果以jason形式返回
131 | $res = curl_exec($ch);
132 | curl_close($ch);
133 | //取出openid
134 | $data = json_decode($res,true);
135 | $this->data = $data;
136 | $openid = $data['openid'];
137 | return $openid;
138 | }
139 |
140 | /**
141 | *
142 | * 拼接签名字符串
143 | * @param array $urlObj
144 | *
145 | * @return 返回已经拼接好的字符串
146 | */
147 | private function ToUrlParams($urlObj)
148 | {
149 | $buff = "";
150 | foreach ($urlObj as $k => $v)
151 | {
152 | if($k != "sign"){
153 | $buff .= $k . "=" . $v . "&";
154 | }
155 | }
156 |
157 | $buff = trim($buff, "&");
158 | return $buff;
159 | }
160 |
161 | /**
162 | *
163 | * 获取地址js参数
164 | *
165 | * @return 获取共享收货地址js函数需要的参数,json格式可以直接做参数使用
166 | */
167 | public function GetEditAddressParameters()
168 | {
169 | $getData = $this->data;
170 | $data = array();
171 | $data["appid"] = WxPayConfig::APPID;
172 | $data["url"] = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
173 | $time = time();
174 | $data["timestamp"] = "$time";
175 | $data["noncestr"] = "1234568";
176 | $data["accesstoken"] = $getData["access_token"];
177 | ksort($data);
178 | $params = $this->ToUrlParams($data);
179 | $addrSign = sha1($params);
180 |
181 | $afterData = array(
182 | "addrSign" => $addrSign,
183 | "signType" => "sha1",
184 | "scope" => "jsapi_address",
185 | "appId" => WxPayConfig::APPID,
186 | "timeStamp" => $data["timestamp"],
187 | "nonceStr" => $data["noncestr"]
188 | );
189 | $parameters = json_encode($afterData);
190 | return $parameters;
191 | }
192 |
193 | /**
194 | *
195 | * 构造获取code的url连接
196 | * @param string $redirectUrl 微信服务器回跳的url,需要url编码
197 | *
198 | * @return 返回构造好的url
199 | */
200 | private function __CreateOauthUrlForCode($redirectUrl)
201 | {
202 | $urlObj["appid"] = WxPayConfig::APPID;
203 | $urlObj["redirect_uri"] = "$redirectUrl";
204 | $urlObj["response_type"] = "code";
205 | $urlObj["scope"] = "snsapi_base";
206 | $urlObj["state"] = "STATE"."#wechat_redirect";
207 | $bizString = $this->ToUrlParams($urlObj);
208 | return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
209 | }
210 |
211 | /**
212 | *
213 | * 构造获取open和access_toke的url地址
214 | * @param string $code,微信跳转带回的code
215 | *
216 | * @return 请求的url
217 | */
218 | private function __CreateOauthUrlForOpenid($code)
219 | {
220 | $urlObj["appid"] = WxPayConfig::APPID;
221 | $urlObj["secret"] = WxPayConfig::APPSECRET;
222 | $urlObj["code"] = $code;
223 | $urlObj["grant_type"] = "authorization_code";
224 | $bizString = $this->ToUrlParams($urlObj);
225 | return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
226 | }
227 | }
--------------------------------------------------------------------------------
/weixinJSAPIpay/js.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 微信支付样例-支付
6 |
40 |
41 |
42 |
43 | 该笔订单支付金额为元钱
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/weixinJSAPIpay/jsapi.php:
--------------------------------------------------------------------------------
1 | GetOpenid();
10 | $input = new \WxPayUnifiedOrder();
11 | $input->SetBody("蓝海工具");
12 | $input->SetOut_trade_no(time().'123');
13 | $input->SetTotal_fee("1");
14 | $input->SetTime_start(date("YmdHis"));
15 | $input->SetTime_expire(date("YmdHis", time() + 600));
16 | $input->SetNotify_url("https://mayunqq.com/paynotify/wxnativepay");
17 | $input->SetTrade_type("JSAPI");
18 | $input->SetOpenid($openId);
19 | $order = \WxPayApi::unifiedOrder($input);
20 | //echo '122255444';die;
21 | //echo '统一下单支付单信息
';
22 | //print_r($order);die;
23 | $jsApiParameters = $tools->GetJsApiParameters($order);
24 | //获取共享收货地址js函数参数
25 | //$editAddress = $tools->GetEditAddressParameters();
26 |
27 | //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
28 | /**
29 | * 注意:
30 | * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
31 | * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
32 | * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
33 | */
34 | return $jsApiParameters;
35 | }
36 | }
37 |
38 |
39 | ?>
40 |
--------------------------------------------------------------------------------
/weixinJSAPIpay/native.php:
--------------------------------------------------------------------------------
1 | SetBody("蓝海工具");
12 | $input->SetOut_trade_no($data['oid']);//订单号
13 | $input->SetTotal_fee("1");//支付金额 单位分
14 | $input->SetTime_start(date("YmdHis"));
15 | $input->SetTime_expire(date("YmdHis", time() + 600));
16 | $input->SetGoods_tag("蓝海工具");
17 | $input->SetNotify_url("https://api.lanhaitools.com/paynotify/wxnativepay");
18 | $input->SetTrade_type("NATIVE");
19 | $input->SetProduct_id($data['oid']);//订单id
20 | $result = $notify->GetPayUrl($input);
21 | if(isset($result["code_url"])){
22 | $url2 = $result["code_url"];
23 | return $url2;
24 | }
25 |
26 | }
27 | }
28 |
29 |
30 | ?>
31 |
--------------------------------------------------------------------------------
/weixinNATIVEpay/WxPay.Api.php:
--------------------------------------------------------------------------------
1 | IsOut_trade_noSet()) {
29 | throw new WxPayException("缺少统一支付接口必填参数out_trade_no!");
30 | }else if(!$inputObj->IsBodySet()){
31 | throw new WxPayException("缺少统一支付接口必填参数body!");
32 | }else if(!$inputObj->IsTotal_feeSet()) {
33 | throw new WxPayException("缺少统一支付接口必填参数total_fee!");
34 | }else if(!$inputObj->IsTrade_typeSet()) {
35 | throw new WxPayException("缺少统一支付接口必填参数trade_type!");
36 | }
37 |
38 | //关联参数
39 | if($inputObj->GetTrade_type() == "JSAPI" && !$inputObj->IsOpenidSet()){
40 | throw new WxPayException("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!");
41 | }
42 | if($inputObj->GetTrade_type() == "NATIVE" && !$inputObj->IsProduct_idSet()){
43 | throw new WxPayException("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
44 | }
45 |
46 | //异步通知url未设置,则使用配置文件中的url
47 | if(!$inputObj->IsNotify_urlSet()){
48 | $inputObj->SetNotify_url(WxPayConfig::NOTIFY_URL);//异步通知url
49 | }
50 |
51 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
52 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
53 | $inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
54 | //$inputObj->SetSpbill_create_ip("1.1.1.1");
55 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
56 |
57 | //签名
58 | $inputObj->SetSign();
59 | $xml = $inputObj->ToXml();
60 | $startTimeStamp = self::getMillisecond();//请求开始时间
61 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
62 | //echo $response;die;
63 | $result = WxPayResults::Init($response);
64 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
65 |
66 | return $result;
67 | }
68 |
69 | /**
70 | *
71 | * 查询订单,WxPayOrderQuery中out_trade_no、transaction_id至少填一个
72 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
73 | * @param WxPayOrderQuery $inputObj
74 | * @param int $timeOut
75 | * @throws WxPayException
76 | * @return 成功时返回,其他抛异常
77 | */
78 | public static function orderQuery($inputObj, $timeOut = 6)
79 | {
80 | $url = "https://api.mch.weixin.qq.com/pay/orderquery";
81 | //检测必填参数
82 | if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
83 | throw new WxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!");
84 | }
85 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
86 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
87 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
88 |
89 | $inputObj->SetSign();//签名
90 | $xml = $inputObj->ToXml();
91 |
92 | $startTimeStamp = self::getMillisecond();//请求开始时间
93 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
94 | $result = WxPayResults::Init($response);
95 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
96 |
97 | return $result;
98 | }
99 |
100 | /**
101 | *
102 | * 关闭订单,WxPayCloseOrder中out_trade_no必填
103 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
104 | * @param WxPayCloseOrder $inputObj
105 | * @param int $timeOut
106 | * @throws WxPayException
107 | * @return 成功时返回,其他抛异常
108 | */
109 | public static function closeOrder($inputObj, $timeOut = 6)
110 | {
111 | $url = "https://api.mch.weixin.qq.com/pay/closeorder";
112 | //检测必填参数
113 | if(!$inputObj->IsOut_trade_noSet()) {
114 | throw new WxPayException("订单查询接口中,out_trade_no必填!");
115 | }
116 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
117 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
118 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
119 |
120 | $inputObj->SetSign();//签名
121 | $xml = $inputObj->ToXml();
122 |
123 | $startTimeStamp = self::getMillisecond();//请求开始时间
124 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
125 | $result = WxPayResults::Init($response);
126 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
127 |
128 | return $result;
129 | }
130 |
131 | /**
132 | *
133 | * 申请退款,WxPayRefund中out_trade_no、transaction_id至少填一个且
134 | * out_refund_no、total_fee、refund_fee、op_user_id为必填参数
135 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
136 | * @param WxPayRefund $inputObj
137 | * @param int $timeOut
138 | * @throws WxPayException
139 | * @return 成功时返回,其他抛异常
140 | */
141 | public static function refund($inputObj, $timeOut = 6)
142 | {
143 | $url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
144 | //检测必填参数
145 | if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
146 | throw new WxPayException("退款申请接口中,out_trade_no、transaction_id至少填一个!");
147 | }else if(!$inputObj->IsOut_refund_noSet()){
148 | throw new WxPayException("退款申请接口中,缺少必填参数out_refund_no!");
149 | }else if(!$inputObj->IsTotal_feeSet()){
150 | throw new WxPayException("退款申请接口中,缺少必填参数total_fee!");
151 | }else if(!$inputObj->IsRefund_feeSet()){
152 | throw new WxPayException("退款申请接口中,缺少必填参数refund_fee!");
153 | }else if(!$inputObj->IsOp_user_idSet()){
154 | throw new WxPayException("退款申请接口中,缺少必填参数op_user_id!");
155 | }
156 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
157 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
158 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
159 |
160 | $inputObj->SetSign();//签名
161 | $xml = $inputObj->ToXml();
162 | $startTimeStamp = self::getMillisecond();//请求开始时间
163 | $response = self::postXmlCurl($xml, $url, true, $timeOut);
164 | $result = WxPayResults::Init($response);
165 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
166 |
167 | return $result;
168 | }
169 |
170 | /**
171 | *
172 | * 查询退款
173 | * 提交退款申请后,通过调用该接口查询退款状态。退款有一定延时,
174 | * 用零钱支付的退款20分钟内到账,银行卡支付的退款3个工作日后重新查询退款状态。
175 | * WxPayRefundQuery中out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个
176 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
177 | * @param WxPayRefundQuery $inputObj
178 | * @param int $timeOut
179 | * @throws WxPayException
180 | * @return 成功时返回,其他抛异常
181 | */
182 | public static function refundQuery($inputObj, $timeOut = 6)
183 | {
184 | $url = "https://api.mch.weixin.qq.com/pay/refundquery";
185 | //检测必填参数
186 | if(!$inputObj->IsOut_refund_noSet() &&
187 | !$inputObj->IsOut_trade_noSet() &&
188 | !$inputObj->IsTransaction_idSet() &&
189 | !$inputObj->IsRefund_idSet()) {
190 | throw new WxPayException("退款查询接口中,out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个!");
191 | }
192 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
193 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
194 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
195 |
196 | $inputObj->SetSign();//签名
197 | $xml = $inputObj->ToXml();
198 |
199 | $startTimeStamp = self::getMillisecond();//请求开始时间
200 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
201 | $result = WxPayResults::Init($response);
202 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
203 |
204 | return $result;
205 | }
206 |
207 | /**
208 | * 下载对账单,WxPayDownloadBill中bill_date为必填参数
209 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
210 | * @param WxPayDownloadBill $inputObj
211 | * @param int $timeOut
212 | * @throws WxPayException
213 | * @return 成功时返回,其他抛异常
214 | */
215 | public static function downloadBill($inputObj, $timeOut = 6)
216 | {
217 | $url = "https://api.mch.weixin.qq.com/pay/downloadbill";
218 | //检测必填参数
219 | if(!$inputObj->IsBill_dateSet()) {
220 | throw new WxPayException("对账单接口中,缺少必填参数bill_date!");
221 | }
222 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
223 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
224 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
225 |
226 | $inputObj->SetSign();//签名
227 | $xml = $inputObj->ToXml();
228 |
229 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
230 | if(substr($response, 0 , 5) == ""){
231 | return "";
232 | }
233 | return $response;
234 | }
235 |
236 | /**
237 | * 提交被扫支付API
238 | * 收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台,
239 | * 由商户收银台或者商户后台调用该接口发起支付。
240 | * WxPayWxPayMicroPay中body、out_trade_no、total_fee、auth_code参数必填
241 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
242 | * @param WxPayWxPayMicroPay $inputObj
243 | * @param int $timeOut
244 | */
245 | public static function micropay($inputObj, $timeOut = 10)
246 | {
247 | $url = "https://api.mch.weixin.qq.com/pay/micropay";
248 | //检测必填参数
249 | if(!$inputObj->IsBodySet()) {
250 | throw new WxPayException("提交被扫支付API接口中,缺少必填参数body!");
251 | } else if(!$inputObj->IsOut_trade_noSet()) {
252 | throw new WxPayException("提交被扫支付API接口中,缺少必填参数out_trade_no!");
253 | } else if(!$inputObj->IsTotal_feeSet()) {
254 | throw new WxPayException("提交被扫支付API接口中,缺少必填参数total_fee!");
255 | } else if(!$inputObj->IsAuth_codeSet()) {
256 | throw new WxPayException("提交被扫支付API接口中,缺少必填参数auth_code!");
257 | }
258 |
259 | $inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
260 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
261 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
262 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
263 |
264 | $inputObj->SetSign();//签名
265 | $xml = $inputObj->ToXml();
266 |
267 | $startTimeStamp = self::getMillisecond();//请求开始时间
268 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
269 | $result = WxPayResults::Init($response);
270 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
271 |
272 | return $result;
273 | }
274 |
275 | /**
276 | *
277 | * 撤销订单API接口,WxPayReverse中参数out_trade_no和transaction_id必须填写一个
278 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
279 | * @param WxPayReverse $inputObj
280 | * @param int $timeOut
281 | * @throws WxPayException
282 | */
283 | public static function reverse($inputObj, $timeOut = 6)
284 | {
285 | $url = "https://api.mch.weixin.qq.com/secapi/pay/reverse";
286 | //检测必填参数
287 | if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
288 | throw new WxPayException("撤销订单API接口中,参数out_trade_no和transaction_id必须填写一个!");
289 | }
290 |
291 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
292 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
293 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
294 |
295 | $inputObj->SetSign();//签名
296 | $xml = $inputObj->ToXml();
297 |
298 | $startTimeStamp = self::getMillisecond();//请求开始时间
299 | $response = self::postXmlCurl($xml, $url, true, $timeOut);
300 | $result = WxPayResults::Init($response);
301 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
302 |
303 | return $result;
304 | }
305 |
306 | /**
307 | *
308 | * 测速上报,该方法内部封装在report中,使用时请注意异常流程
309 | * WxPayReport中interface_url、return_code、result_code、user_ip、execute_time_必填
310 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
311 | * @param WxPayReport $inputObj
312 | * @param int $timeOut
313 | * @throws WxPayException
314 | * @return 成功时返回,其他抛异常
315 | */
316 | public static function report($inputObj, $timeOut = 1)
317 | {
318 | $url = "https://api.mch.weixin.qq.com/payitil/report";
319 | //检测必填参数
320 | if(!$inputObj->IsInterface_urlSet()) {
321 | throw new WxPayException("接口URL,缺少必填参数interface_url!");
322 | } if(!$inputObj->IsReturn_codeSet()) {
323 | throw new WxPayException("返回状态码,缺少必填参数return_code!");
324 | } if(!$inputObj->IsResult_codeSet()) {
325 | throw new WxPayException("业务结果,缺少必填参数result_code!");
326 | } if(!$inputObj->IsUser_ipSet()) {
327 | throw new WxPayException("访问接口IP,缺少必填参数user_ip!");
328 | } if(!$inputObj->IsExecute_time_Set()) {
329 | throw new WxPayException("接口耗时,缺少必填参数execute_time_!");
330 | }
331 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
332 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
333 | $inputObj->SetUser_ip($_SERVER['REMOTE_ADDR']);//终端ip
334 | $inputObj->SetTime(date("YmdHis"));//商户上报时间
335 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
336 |
337 | $inputObj->SetSign();//签名
338 | $xml = $inputObj->ToXml();
339 |
340 | $startTimeStamp = self::getMillisecond();//请求开始时间
341 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
342 | return $response;
343 | }
344 |
345 | /**
346 | *
347 | * 生成二维码规则,模式一生成支付二维码
348 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
349 | * @param WxPayBizPayUrl $inputObj
350 | * @param int $timeOut
351 | * @throws WxPayException
352 | * @return 成功时返回,其他抛异常
353 | */
354 | public static function bizpayurl($inputObj, $timeOut = 6)
355 | {
356 | if(!$inputObj->IsProduct_idSet()){
357 | throw new WxPayException("生成二维码,缺少必填参数product_id!");
358 | }
359 |
360 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
361 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
362 | $inputObj->SetTime_stamp(time());//时间戳
363 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
364 |
365 | $inputObj->SetSign();//签名
366 |
367 | return $inputObj->GetValues();
368 | }
369 |
370 | /**
371 | *
372 | * 转换短链接
373 | * 该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX),
374 | * 减小二维码数据量,提升扫描速度和精确度。
375 | * appid、mchid、spbill_create_ip、nonce_str不需要填入
376 | * @param WxPayShortUrl $inputObj
377 | * @param int $timeOut
378 | * @throws WxPayException
379 | * @return 成功时返回,其他抛异常
380 | */
381 | public static function shorturl($inputObj, $timeOut = 6)
382 | {
383 | $url = "https://api.mch.weixin.qq.com/tools/shorturl";
384 | //检测必填参数
385 | if(!$inputObj->IsLong_urlSet()) {
386 | throw new WxPayException("需要转换的URL,签名用原串,传输需URL encode!");
387 | }
388 | $inputObj->SetAppid(WxPayConfig::APPID);//公众账号ID
389 | $inputObj->SetMch_id(WxPayConfig::MCHID);//商户号
390 | $inputObj->SetNonce_str(self::getNonceStr());//随机字符串
391 |
392 | $inputObj->SetSign();//签名
393 | $xml = $inputObj->ToXml();
394 |
395 | $startTimeStamp = self::getMillisecond();//请求开始时间
396 | $response = self::postXmlCurl($xml, $url, false, $timeOut);
397 | $result = WxPayResults::Init($response);
398 | self::reportCostTime($url, $startTimeStamp, $result);//上报请求花费时间
399 |
400 | return $result;
401 | }
402 |
403 | /**
404 | *
405 | * 支付结果通用通知
406 | * @param function $callback
407 | * 直接回调函数使用方法: notify(you_function);
408 | * 回调类成员函数方法:notify(array($this, you_function));
409 | * $callback 原型为:function function_name($data){}
410 | */
411 | public static function notify($callback, &$msg)
412 | {
413 | //获取通知的数据
414 | $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
415 | //如果返回成功则验证签名
416 | try {
417 | $result = WxPayResults::Init($xml);
418 | } catch (WxPayException $e){
419 | $msg = $e->errorMessage();
420 | return false;
421 | }
422 |
423 | return call_user_func($callback, $result);
424 | }
425 |
426 | /**
427 | *
428 | * 产生随机字符串,不长于32位
429 | * @param int $length
430 | * @return 产生的随机字符串
431 | */
432 | public static function getNonceStr($length = 32)
433 | {
434 | $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
435 | $str ="";
436 | for ( $i = 0; $i < $length; $i++ ) {
437 | $str .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
438 | }
439 | return $str;
440 | }
441 |
442 | /**
443 | * 直接输出xml
444 | * @param string $xml
445 | */
446 | public static function replyNotify($xml)
447 | {
448 | echo $xml;
449 | }
450 |
451 | /**
452 | *
453 | * 上报数据, 上报的时候将屏蔽所有异常流程
454 | * @param string $usrl
455 | * @param int $startTimeStamp
456 | * @param array $data
457 | */
458 | private static function reportCostTime($url, $startTimeStamp, $data)
459 | {
460 | //如果不需要上报数据
461 | if(WxPayConfig::REPORT_LEVENL == 0){
462 | return;
463 | }
464 | //如果仅失败上报
465 | if(WxPayConfig::REPORT_LEVENL == 1 &&
466 | array_key_exists("return_code", $data) &&
467 | $data["return_code"] == "SUCCESS" &&
468 | array_key_exists("result_code", $data) &&
469 | $data["result_code"] == "SUCCESS")
470 | {
471 | return;
472 | }
473 |
474 | //上报逻辑
475 | $endTimeStamp = self::getMillisecond();
476 | $objInput = new WxPayReport();
477 | $objInput->SetInterface_url($url);
478 | $objInput->SetExecute_time_($endTimeStamp - $startTimeStamp);
479 | //返回状态码
480 | if(array_key_exists("return_code", $data)){
481 | $objInput->SetReturn_code($data["return_code"]);
482 | }
483 | //返回信息
484 | if(array_key_exists("return_msg", $data)){
485 | $objInput->SetReturn_msg($data["return_msg"]);
486 | }
487 | //业务结果
488 | if(array_key_exists("result_code", $data)){
489 | $objInput->SetResult_code($data["result_code"]);
490 | }
491 | //错误代码
492 | if(array_key_exists("err_code", $data)){
493 | $objInput->SetErr_code($data["err_code"]);
494 | }
495 | //错误代码描述
496 | if(array_key_exists("err_code_des", $data)){
497 | $objInput->SetErr_code_des($data["err_code_des"]);
498 | }
499 | //商户订单号
500 | if(array_key_exists("out_trade_no", $data)){
501 | $objInput->SetOut_trade_no($data["out_trade_no"]);
502 | }
503 | //设备号
504 | if(array_key_exists("device_info", $data)){
505 | $objInput->SetDevice_info($data["device_info"]);
506 | }
507 |
508 | try{
509 | self::report($objInput);
510 | } catch (WxPayException $e){
511 | //不做任何处理
512 | }
513 | }
514 |
515 | /**
516 | * 以post方式提交xml到对应的接口url
517 | *
518 | * @param string $xml 需要post的xml数据
519 | * @param string $url url
520 | * @param bool $useCert 是否需要证书,默认不需要
521 | * @param int $second url执行超时时间,默认30s
522 | * @throws WxPayException
523 | */
524 | private static function postXmlCurl($xml, $url, $useCert = false, $second = 30)
525 | {
526 | $ch = curl_init();
527 | //设置超时
528 | curl_setopt($ch, CURLOPT_TIMEOUT, $second);
529 |
530 | //如果有配置代理这里就设置代理
531 | if(WxPayConfig::CURL_PROXY_HOST != "0.0.0.0"
532 | && WxPayConfig::CURL_PROXY_PORT != 0){
533 | curl_setopt($ch,CURLOPT_PROXY, WxPayConfig::CURL_PROXY_HOST);
534 | curl_setopt($ch,CURLOPT_PROXYPORT, WxPayConfig::CURL_PROXY_PORT);
535 | }
536 | curl_setopt($ch,CURLOPT_URL, $url);
537 | //curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE);
538 | curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);//2017-05-26 修改
539 | //curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);//严格校验
540 | curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);//严格校验
541 | //设置header
542 | curl_setopt($ch, CURLOPT_HEADER, FALSE);
543 | //要求结果为字符串且输出到屏幕上
544 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
545 |
546 | if($useCert == true){
547 | //设置证书
548 | //使用证书:cert 与 key 分别属于两个.pem文件
549 | curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
550 | curl_setopt($ch,CURLOPT_SSLCERT, WxPayConfig::SSLCERT_PATH);
551 | curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
552 | curl_setopt($ch,CURLOPT_SSLKEY, WxPayConfig::SSLKEY_PATH);
553 | }
554 | //post提交方式
555 | curl_setopt($ch, CURLOPT_POST, TRUE);
556 | curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
557 | //运行curl
558 | $data = curl_exec($ch);
559 | //echo $data;die;
560 | //返回结果
561 | if($data){
562 | //echo '33333333333333';die;
563 | curl_close($ch);
564 | return $data;
565 | } else {
566 | //echo '222222222222';die;
567 | $error = curl_errno($ch);
568 | curl_close($ch);
569 | throw new WxPayException("curl出错,错误码:$error");
570 | }
571 | }
572 |
573 | /**
574 | * 获取毫秒级别的时间戳
575 | */
576 | private static function getMillisecond()
577 | {
578 | //获取毫秒的时间戳
579 | $time = explode ( " ", microtime () );
580 | $time = $time[1] . ($time[0] * 1000);
581 | $time2 = explode( ".", $time );
582 | $time = $time2[0];
583 | return $time;
584 | }
585 | }
586 |
587 |
--------------------------------------------------------------------------------
/weixinNATIVEpay/WxPay.Config.php:
--------------------------------------------------------------------------------
1 | getMessage();
12 | }
13 | }
--------------------------------------------------------------------------------
/weixinNATIVEpay/WxPay.NativePay.php:
--------------------------------------------------------------------------------
1 | SetProduct_id($productId);
21 | $values = WxpayApi::bizpayurl($biz);
22 | $url = "weixin://wxpay/bizpayurl?" . $this->ToUrlParams($values);
23 | return $url;
24 | }
25 |
26 | /**
27 | *
28 | * 参数数组转换为url参数
29 | * @param array $urlObj
30 | */
31 | private function ToUrlParams($urlObj)
32 | {
33 | $buff = "";
34 | foreach ($urlObj as $k => $v)
35 | {
36 | $buff .= $k . "=" . $v . "&";
37 | }
38 |
39 | $buff = trim($buff, "&");
40 | return $buff;
41 | }
42 |
43 | /**
44 | *
45 | * 生成直接支付url,支付url有效期为2小时,模式二
46 | * @param UnifiedOrderInput $input
47 | */
48 | public function GetPayUrl($input)
49 | {
50 | if($input->GetTrade_type() == "NATIVE")
51 | {
52 | $result = WxPayApi::unifiedOrder($input);
53 | return $result;
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/weixinNATIVEpay/native.php:
--------------------------------------------------------------------------------
1 | SetBody("蓝海工具");
12 | $input->SetOut_trade_no($data['oid']);//订单号
13 | $input->SetTotal_fee("1");//支付金额 单位分
14 | $input->SetTime_start(date("YmdHis"));
15 | $input->SetTime_expire(date("YmdHis", time() + 600));
16 | $input->SetGoods_tag("蓝海工具");
17 | $input->SetNotify_url("https://api.lanhaitools.com/paynotify/wxnativepay");
18 | $input->SetTrade_type("NATIVE");
19 | $input->SetProduct_id($data['oid']);//订单id
20 | $result = $notify->GetPayUrl($input);
21 | if(isset($result["code_url"])){
22 | $url2 = $result["code_url"];
23 | return $url2;
24 | }
25 |
26 | }
27 | }
28 |
29 |
30 | ?>
31 |
--------------------------------------------------------------------------------
/weixinNOTIFY/notify.php:
--------------------------------------------------------------------------------
1 | getNotifyData();//获取数据(微信服务器返回的数据)
9 |
10 | $w_sign = array(); //参加验签签名的参数数组
11 | $w_sign['appid'] = $arr['appid'];
12 | $w_sign['bank_type'] = $arr['bank_type'];
13 | $w_sign['cash_fee'] = $arr['cash_fee'];
14 | $w_sign['fee_type'] = $arr['fee_type'];
15 | $w_sign['is_subscribe'] = $arr['is_subscribe'];
16 | $w_sign['mch_id'] = $arr['mch_id'];
17 | $w_sign['nonce_str'] = $arr['nonce_str'];
18 | $w_sign['openid'] = $arr['openid'];
19 | $w_sign['out_trade_no'] = $arr['out_trade_no'];
20 | $w_sign['result_code'] = $arr['result_code'];
21 | $w_sign['return_code'] = $arr['return_code'];
22 | $w_sign['time_end'] = $arr['time_end'];
23 | $w_sign['total_fee'] = $arr['total_fee'];
24 | $w_sign['trade_type'] = $arr['trade_type'];
25 | $w_sign['transaction_id'] = $arr['transaction_id'];
26 | //生成签名
27 | $verify_sign = $checkSign->MakeSign($w_sign);
28 |
29 | if($arr['result_code'] == 'SUCCESS' && $verify_sign == $arr['sign']){//验证签名
30 | $data= ['oid'=>$arr['out_trade_no'],'buyerid'=>$arr['openid'],'trade_no'=>$arr['transaction_id'],'receipt'=>$arr['total_fee']];
31 |
32 | $ret = AfterPayOrder($data,$return_url);//自己写修改订单状态 付款状态===
33 | if(!$ret){
34 | //('订单支付成功后,状态操作失败'.$_POST['out_trade_no']);
35 | }else{
36 |
37 | $checkSign->replyNotify();//操做成功 通知微信 停止异步通知
38 | }
39 | }else{
40 | $msg = isset($arr['out_trade_no'])?'订单:'.$arr['out_trade_no']:'支付时间:'.date('Y-m-d H:i:s',time());
41 | //$msg.'异步通知失败,请联系开发人员'
42 | }
43 |
44 |
45 |
46 | ?>
47 |
--------------------------------------------------------------------------------
/weixinNOTIFY/wechatAppPay.php:
--------------------------------------------------------------------------------
1 | //填写微信分配的公众账号ID
8 | * 'mch_id' => //填写微信支付分配的商户号
9 | * 'notify_url'=> //填写微信支付结果回调地址
10 | * 'key' => //填写微信商户支付密钥
11 | * );
12 | * 统一下单方法
13 | * $WechatAppPay = new wechatAppPay($options);
14 | * $params['body'] = '商品描述'; //商品描述
15 | * $params['out_trade_no'] = '1217752501201407'; //自定义的订单号,不能重复
16 | * $params['total_fee'] = '100'; //订单金额 只能为整数 单位为分
17 | * $params['trade_type'] = 'APP'; //交易类型 JSAPI | NATIVE |APP | WAP
18 | * $wechatAppPay->unifiedOrder( $params );
19 | */
20 | class wechatAppPay
21 | {
22 | //接口API URL前缀
23 | const API_URL_PREFIX = 'https://api.mch.weixin.qq.com';
24 | //下单地址URL
25 | const UNIFIEDORDER_URL = "/pay/unifiedorder";
26 | //查询订单URL
27 | const ORDERQUERY_URL = "/pay/orderquery";
28 | //关闭订单URL
29 | const CLOSEORDER_URL = "/pay/closeorder";
30 | //公众账号ID
31 | private $appid;
32 | //商户号
33 | private $mch_id;
34 | //随机字符串
35 | private $nonce_str;
36 | //签名
37 | private $sign;
38 | //商品描述
39 | private $body;
40 | //商户订单号
41 | private $out_trade_no;
42 | //支付总金额
43 | private $total_fee;
44 | //终端IP
45 | private $spbill_create_ip;
46 | //支付结果回调通知地址
47 | private $notify_url;
48 | //交易类型
49 | private $trade_type;
50 | //支付密钥
51 | private $key;
52 | //证书路径
53 | private $SSLCERT_PATH;
54 | private $SSLKEY_PATH;
55 | //所有参数
56 | private $params = array();
57 | public function __construct($appid, $mch_id, $notify_url, $key)
58 | {
59 | $this->appid = $appid;
60 | $this->mch_id = $mch_id;
61 | $this->notify_url = $notify_url;
62 | $this->key = $key;
63 | }
64 | /**
65 | * 下单方法
66 | * @param $params 下单参数
67 | */
68 | public function unifiedOrder( $params ){
69 | $this->body = $params['body'];
70 | $this->out_trade_no = $params['out_trade_no'];
71 | $this->total_fee = $params['total_fee'];
72 | $this->trade_type = $params['trade_type'];
73 | $this->nonce_str = $this->genRandomString();
74 | $this->spbill_create_ip = $_SERVER['REMOTE_ADDR'];
75 | $this->params['appid'] = $this->appid;
76 | $this->params['mch_id'] = $this->mch_id;
77 | $this->params['nonce_str'] = $this->nonce_str;
78 | $this->params['body'] = $this->body;
79 | $this->params['out_trade_no'] = $this->out_trade_no;
80 | $this->params['total_fee'] = $this->total_fee;
81 | $this->params['spbill_create_ip'] = $this->spbill_create_ip;
82 | $this->params['notify_url'] = $this->notify_url;
83 | $this->params['trade_type'] = $this->trade_type;
84 | //获取签名数据
85 | $this->sign = $this->MakeSign( $this->params );
86 | $this->params['sign'] = $this->sign;
87 | $xml = $this->data_to_xml($this->params);
88 | $response = $this->postXmlCurl($xml, self::API_URL_PREFIX.self::UNIFIEDORDER_URL);
89 | if( !$response ){
90 | return false;
91 | }
92 | $result = $this->xml_to_data( $response );
93 | if( !empty($result['result_code']) && !empty($result['err_code']) ){
94 | $result['err_msg'] = $this->error_code( $result['err_code'] );
95 | }
96 | return $result;
97 | }
98 | /**
99 | * 查询订单信息
100 | * @param $out_trade_no 订单号
101 | * @return array
102 | */
103 | public function orderQuery( $out_trade_no ){
104 | $this->params['appid'] = $this->appid;
105 | $this->params['mch_id'] = $this->mch_id;
106 | $this->params['nonce_str'] = $this->genRandomString();
107 | $this->params['out_trade_no'] = $out_trade_no;
108 | //获取签名数据
109 | $this->sign = $this->MakeSign( $this->params );
110 | $this->params['sign'] = $this->sign;
111 | $xml = $this->data_to_xml($this->params);
112 | $response = $this->postXmlCurl($xml, self::API_URL_PREFIX.self::ORDERQUERY_URL);
113 | if( !$response ){
114 | return false;
115 | }
116 | $result = $this->xml_to_data( $response );
117 | if( !empty($result['result_code']) && !empty($result['err_code']) ){
118 | $result['err_msg'] = $this->error_code( $result['err_code'] );
119 | }
120 | return $result;
121 | }
122 | /**
123 | * 关闭订单
124 | * @param $out_trade_no 订单号
125 | * @return array
126 | */
127 | public function closeOrder( $out_trade_no ){
128 | $this->params['appid'] = $this->appid;
129 | $this->params['mch_id'] = $this->mch_id;
130 | $this->params['nonce_str'] = $this->genRandomString();
131 | $this->params['out_trade_no'] = $out_trade_no;
132 | //获取签名数据
133 | $this->sign = $this->MakeSign( $this->params );
134 | $this->params['sign'] = $this->sign;
135 | $xml = $this->data_to_xml($this->params);
136 | $response = $this->postXmlCurl($xml, self::API_URL_PREFIX.self::CLOSEORDER_URL);
137 | if( !$response ){
138 | return false;
139 | }
140 | $result = $this->xml_to_data( $response );
141 | return $result;
142 | }
143 | /**
144 | *
145 | * 获取支付结果通知数据
146 | * return array
147 | */
148 | public function getNotifyData(){
149 | //获取通知的数据
150 | $xml = $GLOBALS['HTTP_RAW_POST_DATA'];
151 | //echo 123;die;
152 | $data = array();
153 | if( empty($xml) ){
154 | return false;
155 | }
156 | $data = $this->xml_to_data( $xml );
157 | if( !empty($data['return_code']) ){
158 | if( $data['return_code'] == 'FAIL' ){
159 | return false;
160 | }
161 | }
162 | return $data;
163 | }
164 | /**
165 | * 接收通知成功后应答输出XML数据
166 | * @param string $xml
167 | */
168 | public function replyNotify(){
169 | $data['return_code'] = 'SUCCESS';
170 | $data['return_msg'] = 'OK';
171 | $xml = $this->data_to_xml( $data );
172 | echo $xml;
173 | die();
174 | }
175 | /**
176 | * 生成APP端支付参数
177 | * @param $prepayid 预支付id
178 | */
179 | public function getAppPayParams( $prepayid ){
180 | $data['appid'] = $this->appid;
181 | $data['partnerid'] = $this->mch_id;
182 | $data['prepayid'] = $prepayid;
183 | $data['package'] = 'Sign=WXPay';
184 | $data['noncestr'] = $this->genRandomString();
185 | $data['timestamp'] = time();
186 | $data['sign'] = $this->MakeSign( $data );
187 | return $data;
188 | }
189 | /**
190 | * 生成签名
191 | * @return 签名
192 | */
193 | public function MakeSign( $params ){
194 | //签名步骤一:按字典序排序数组参数
195 | ksort($params);
196 | $string = $this->ToUrlParams($params);
197 | //签名步骤二:在string后加入KEY
198 | $string = $string . "&key=".$this->key;
199 | //签名步骤三:MD5加密
200 | $string = md5($string);
201 | //签名步骤四:所有字符转为大写
202 | $result = strtoupper($string);
203 | return $result;
204 | }
205 | /**
206 | * 将参数拼接为url: key=value&key=value
207 | * @param $params
208 | * @return string
209 | */
210 | public function ToUrlParams( $params ){
211 | $string = '';
212 | if( !empty($params) ){
213 | $array = array();
214 | foreach( $params as $key => $value ){
215 | $array[] = $key.'='.$value;
216 | }
217 | $string = implode("&",$array);
218 | }
219 | return $string;
220 | }
221 | /**
222 | * 输出xml字符
223 | * @param $params 参数名称
224 | * return string 返回组装的xml
225 | **/
226 | public function data_to_xml( $params ){
227 | if(!is_array($params)|| count($params) <= 0)
228 | {
229 | return false;
230 | }
231 | $xml = "";
232 | foreach ($params as $key=>$val)
233 | {
234 | if (is_numeric($val)){
235 | $xml.="<".$key.">".$val."".$key.">";
236 | }else{
237 | $xml.="<".$key.">".$key.">";
238 | }
239 | }
240 | $xml.="";
241 | return $xml;
242 | }
243 | /**
244 | * 将xml转为array
245 | * @param string $xml
246 | * return array
247 | */
248 | public function xml_to_data($xml){
249 | if(!$xml){
250 | return false;
251 | }
252 | //将XML转为array
253 | //禁止引用外部xml实体
254 | libxml_disable_entity_loader(true);
255 | $data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
256 | return $data;
257 | }
258 | /**
259 | * 获取毫秒级别的时间戳
260 | */
261 | private static function getMillisecond(){
262 | //获取毫秒的时间戳
263 | $time = explode ( " ", microtime () );
264 | $time = $time[1] . ($time[0] * 1000);
265 | $time2 = explode( ".", $time );
266 | $time = $time2[0];
267 | return $time;
268 | }
269 | /**
270 | * 产生一个指定长度的随机字符串,并返回给用户
271 | * @param type $len 产生字符串的长度
272 | * @return string 随机字符串
273 | */
274 | private function genRandomString($len = 32) {
275 | $chars = array(
276 | "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
277 | "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
278 | "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
279 | "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
280 | "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
281 | "3", "4", "5", "6", "7", "8", "9"
282 | );
283 | $charsLen = count($chars) - 1;
284 | // 将数组打乱
285 | shuffle($chars);
286 | $output = "";
287 | for ($i = 0; $i < $len; $i++) {
288 | $output .= $chars[mt_rand(0, $charsLen)];
289 | }
290 | return $output;
291 | }
292 | /**
293 | * 以post方式提交xml到对应的接口url
294 | *
295 | * @param string $xml 需要post的xml数据
296 | * @param string $url url
297 | * @param bool $useCert 是否需要证书,默认不需要
298 | * @param int $second url执行超时时间,默认30s
299 | * @throws WxPayException
300 | */
301 | private function postXmlCurl($xml, $url, $useCert = false, $second = 30){
302 | $ch = curl_init();
303 | //设置超时
304 | curl_setopt($ch, CURLOPT_TIMEOUT, $second);
305 | curl_setopt($ch,CURLOPT_URL, $url);
306 | curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
307 | curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);
308 | //设置header
309 | curl_setopt($ch, CURLOPT_HEADER, FALSE);
310 | //要求结果为字符串且输出到屏幕上
311 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
312 | if($useCert == true){
313 | //设置证书
314 | //使用证书:cert 与 key 分别属于两个.pem文件
315 | curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
316 | //curl_setopt($ch,CURLOPT_SSLCERT, WxPayConfig::SSLCERT_PATH);
317 | curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
318 | //curl_setopt($ch,CURLOPT_SSLKEY, WxPayConfig::SSLKEY_PATH);
319 | }
320 | //post提交方式
321 | curl_setopt($ch, CURLOPT_POST, TRUE);
322 | curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
323 | //运行curl
324 | $data = curl_exec($ch);
325 | //返回结果
326 | if($data){
327 | curl_close($ch);
328 | return $data;
329 | } else {
330 | $error = curl_errno($ch);
331 | curl_close($ch);
332 | return false;
333 | }
334 | }
335 | /**
336 | * 错误代码
337 | * @param $code 服务器输出的错误代码
338 | * return string
339 | */
340 | public function error_code( $code ){
341 | $errList = array(
342 | 'NOAUTH' => '商户未开通此接口权限',
343 | 'NOTENOUGH' => '用户帐号余额不足',
344 | 'ORDERNOTEXIST' => '订单号不存在',
345 | 'ORDERPAID' => '商户订单已支付,无需重复操作',
346 | 'ORDERCLOSED' => '当前订单已关闭,无法支付',
347 | 'SYSTEMERROR' => '系统错误!系统超时',
348 | 'APPID_NOT_EXIST' => '参数中缺少APPID',
349 | 'MCHID_NOT_EXIST' => '参数中缺少MCHID',
350 | 'APPID_MCHID_NOT_MATCH' => 'appid和mch_id不匹配',
351 | 'LACK_PARAMS' => '缺少必要的请求参数',
352 | 'OUT_TRADE_NO_USED' => '同一笔交易不能多次提交',
353 | 'SIGNERROR' => '参数签名结果不正确',
354 | 'XML_FORMAT_ERROR' => 'XML格式错误',
355 | 'REQUIRE_POST_METHOD' => '未使用post传递参数 ',
356 | 'POST_DATA_EMPTY' => 'post数据不能为空',
357 | 'NOT_UTF8' => '未使用指定编码格式',
358 | );
359 | if( array_key_exists( $code , $errList ) ){
360 | return $errList[$code];
361 | }
362 | }
363 | }
364 |
365 |
366 |
367 |
368 |
369 |
--------------------------------------------------------------------------------