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