66 */
77namespace hillpy \MiniProgramSDK ;
88
9+ include "Common.php " ;
10+
911class MiniProgram
1012{
1113 private $ appId = '' ;
@@ -50,7 +52,7 @@ public function getAccessTokenData()
5052 'secret ' =>$ this ->appSecret
5153 );
5254 $ url = self ::API_HOST . self ::ACCESS_TOKEN_PATH . http_build_query ($ urlParamArr );
53- $ res = json_decode ($ this -> http_request ($ url ), true );
55+ $ res = json_decode (Common:: httpRequest ($ url ), true );
5456 if ($ res ['errcode ' ]) {
5557 return '' ;
5658 } else {
@@ -72,7 +74,7 @@ public function jscode2Session($code)
7274 'grant_type ' =>'authorization_code '
7375 );
7476 $ url = self ::API_HOST . self ::JSCODE_2_SESSSION_PATH . http_build_query ($ urlParamArr );
75- $ res = json_decode ($ this -> http_request ($ url ),true );
77+ $ res = json_decode (Common:: httpRequest ($ url ),true );
7678 return $ res ;
7779 }
7880
@@ -156,7 +158,7 @@ public function getWXACode($postParamArr = array())
156158 'access_token ' =>$ this ->accessToken
157159 );
158160 $ url = self ::API_HOST . self ::WXACODE_PATH . http_build_query ($ urlParamArr );
159- $ res = $ this -> http_request ($ url , json_encode ($ postParamArr ));
161+ $ res = Common:: httpRequest ($ url , json_encode ($ postParamArr ));
160162 return $ res ;
161163 }
162164
@@ -171,32 +173,10 @@ public function getWxacodeUnlimit($postParamArr = array())
171173 'access_token ' =>$ this ->accessToken
172174 );
173175 $ url = self ::API_HOST . self ::WXACODE_UNLIMIT_PATH . http_build_query ($ urlParamArr );
174- $ res = $ this -> http_request ($ url , json_encode ($ postParamArr ));
176+ $ res = Common:: httpRequest ($ url , json_encode ($ postParamArr ));
175177 return $ res ;
176178 }
177179
178- /**
179- * http请求函数
180- * @param $url
181- * @param null $data
182- * @return mixed
183- */
184- private function http_request ($ url , $ data = null )
185- {
186- $ curl = curl_init ();
187- curl_setopt ($ curl , CURLOPT_URL , $ url );
188- curl_setopt ($ curl , CURLOPT_SSL_VERIFYPEER , false );
189- curl_setopt ($ curl , CURLOPT_SSL_VERIFYHOST , false );
190- if (!empty ($ data )) {
191- curl_setopt ($ curl , CURLOPT_POST , true );
192- curl_setopt ($ curl , CURLOPT_POSTFIELDS , $ data );
193- }
194- curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
195- $ output = curl_exec ($ curl );
196- curl_close ($ curl );
197- return $ output ;
198- }
199-
200180 /**
201181 * 获取随机字符串
202182 * @param int $length
0 commit comments