You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.9 KiB
67 lines
1.9 KiB
<?php
|
|
|
|
namespace zixishi;
|
|
|
|
|
|
class Base
|
|
{
|
|
|
|
protected $token = '';
|
|
// 正式平台接口URL
|
|
protected $url = "https://login.haoyuexia.com/foreign/";
|
|
// 测试平台接口URL
|
|
// protected $url = "https://zxsmenjin.jucheng01.net/foreign/";
|
|
|
|
// 配置
|
|
protected $config;
|
|
|
|
/**
|
|
* 构造函数
|
|
* @date 2022-08-02
|
|
*/
|
|
public function __construct(array $data = [])
|
|
{
|
|
$this->config = $data;
|
|
}
|
|
|
|
|
|
/**
|
|
* 发送请求
|
|
* @date 2022-08-02
|
|
*/
|
|
protected function httpPData($url, $data, $aHeader, $requests_num = 0)
|
|
{
|
|
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_REFERER, request()->domain());
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
$status = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
$result = json_decode($status, true);
|
|
/*判断是否返回token失效*/
|
|
// if ($result['code'] == 7006) {
|
|
// if ($requests_num <= 0) {
|
|
// foreach ($aHeader as $key => $value) {
|
|
// $temp_data = explode(':', $value);
|
|
// if ($temp_data[0] == 'token') {
|
|
// $temp_data = json_decode($data, true);
|
|
// if (!empty($temp_data['device_number'])) {
|
|
// $token = $this->getRAccessToken($temp_data['device_number'], 1);//重新获取
|
|
// $aHeader[$key] = 'token:' . $token;
|
|
// }
|
|
// }
|
|
// }
|
|
// $result = $this->httpPData($url, $temp_data, $aHeader, 1);
|
|
// }
|
|
// }
|
|
return $result;
|
|
}
|
|
|
|
|
|
} |