|
@@ -94,7 +94,7 @@ class GmService
|
|
|
// dump($data);
|
|
|
// exit;
|
|
|
//发送post接口请求
|
|
|
- $res = self::https_post(self::$tokenUrl, $data);
|
|
|
+ $res = self::do_request(self::$tokenUrl, $data);
|
|
|
|
|
|
//解密返回token数据
|
|
|
$token = self::SM2Decrypt(base64_decode($res['sm2EncryptData']), $k1);
|
|
@@ -384,7 +384,7 @@ class GmService
|
|
|
private static function https_post($url, $data = null)
|
|
|
{
|
|
|
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
|
|
- $header [] = 'Content-Type:application/x-www-form-urlencoded';
|
|
|
+ $header[] = 'Content-Type:application/x-www-form-urlencoded';
|
|
|
$ch = curl_init();
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
@@ -401,6 +401,29 @@ class GmService
|
|
|
return json_decode($tmpInfo, true);
|
|
|
}
|
|
|
|
|
|
+ private static function do_request($url, $data)
|
|
|
+ {
|
|
|
+ $data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
|
|
+ $header[] = 'Content-Type:application/x-www-form-urlencoded';
|
|
|
+ $curl = curl_init();
|
|
|
+ curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ curl_setopt($curl, CURLOPT_POST, 1);
|
|
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
|
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ if ($header) {
|
|
|
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
|
|
+ curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
|
+ }
|
|
|
+ $result = curl_exec($curl);
|
|
|
+ if (curl_errno($curl)) {
|
|
|
+ return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
|
|
|
+ }
|
|
|
+ curl_close($curl);
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获得随机字符串
|
|
|
**/
|