@@ -16,12 +16,15 @@ class MiniProgram
1616 const API_HOST = 'https://api.weixin.qq.com ' ;
1717 const ACCESS_TOKEN_PATH = '/cgi-bin/token? ' ;
1818 const JSCODE_2_SESSSION_PATH = '/sns/jscode2session? ' ;
19+ const WXAQRCODE_PATH = '/cgi-bin/wxaapp/createwxaqrcode? ' ;
20+ const WXACODE_PATH = '/wxa/getwxacode? ' ;
1921 const WXACODE_UNLIMIT_PATH = '/wxa/getwxacodeunlimit? ' ;
2022
2123 /**
22- * MiniProgramApi constructor.
24+ * MiniProgram constructor.
2325 * @param $appId
2426 * @param $appSecret
27+ * @param string $accessToken
2528 */
2629 public function __construct ($ appId , $ appSecret , $ accessToken = '' )
2730 {
@@ -35,7 +38,10 @@ public function __construct($appId, $appSecret, $accessToken = '')
3538 }
3639 }
3740
38-
41+ /**
42+ * 获取accessToken
43+ * @return mixed|string
44+ */
3945 public function getAccessTokenData ()
4046 {
4147 $ urlParamArr = array (
@@ -53,7 +59,25 @@ public function getAccessTokenData()
5359 }
5460
5561 /**
56- * 小程序登录解密用户数据
62+ * 获取openid、sessionKey
63+ * @param $code
64+ * @return mixed
65+ */
66+ public function jscode2Session ($ code )
67+ {
68+ $ urlParamArr = array (
69+ 'appid ' =>$ this ->appId ,
70+ 'secret ' =>$ this ->appSecret ,
71+ 'js_code ' =>$ code ,
72+ 'grant_type ' =>'authorization_code '
73+ );
74+ $ url = self ::API_HOST . self ::JSCODE_2_SESSSION_PATH . http_build_query ($ urlParamArr );
75+ $ res = json_decode ($ this ->http_request ($ url ),true );
76+ return $ res ;
77+ }
78+
79+ /**
80+ * 解密微信用户的加密数据包
5781 * @param array $params
5882 * @return mixed
5983 */
@@ -107,25 +131,38 @@ public function decryptData($paramArr = array())
107131 }
108132
109133 /**
110- * 获取openid、sessionKey接口
111- * @param $code
134+ * 获取小程序二维码
135+ * @param array $postParamArr
112136 * @return mixed
113137 */
114- public function jscode2Session ( $ code )
138+ public function createWXAQRCode ( $ postParamArr = array () )
115139 {
116140 $ urlParamArr = array (
117- 'appid ' =>$ this ->appId ,
118- 'secret ' =>$ this ->appSecret ,
119- 'js_code ' =>$ code ,
120- 'grant_type ' =>'authorization_code '
141+ 'access_token ' =>$ this ->accessToken
121142 );
122- $ url = self ::API_HOST . self ::JSCODE_2_SESSSION_PATH . http_build_query ($ urlParamArr );
123- $ res = json_decode ($ this ->http_request ($ url ),true );
143+ $ url = self ::API_HOST . self ::WXAQRCODE_PATH . http_build_query ($ urlParamArr );
144+ $ res = $ this ->http_request ($ url , json_encode ($ postParamArr ));
145+ return $ res ;
146+ }
147+
148+ /**
149+ * 获取小程序码
150+ * @param array $postParamArr
151+ * @return mixed
152+ */
153+ public function getWXACode ($ postParamArr = array ())
154+ {
155+ $ urlParamArr = array (
156+ 'access_token ' =>$ this ->accessToken
157+ );
158+ $ url = self ::API_HOST . self ::WXACODE_PATH . http_build_query ($ urlParamArr );
159+ $ res = $ this ->http_request ($ url , json_encode ($ postParamArr ));
124160 return $ res ;
125161 }
126162
127163 /**
128164 * 获取小程序码(无数量限制)
165+ * @param array $postParamArr
129166 * @return mixed
130167 */
131168 public function getWxacodeUnlimit ($ postParamArr = array ())
0 commit comments