curl($url); return json_decode($res, true); } /** * 请求接口 * @param $url * @param null $data * @return mixed|null */ protected function curl($url, $data=null) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-type: application/json; encoding=utf-8']); if (!empty($data)) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_HEADER, false); $data = curl_exec($curl); curl_close($curl); return $data; } /** * -JS-SDK使用权限签名算法 * @param $accesstoken */ public function getTicket($accesstoken) { $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$accesstoken.'&type=jsapi'; $res = $this->curl($url); return json_decode($res, true); } /** * 普通access_token */ public function AccessToken($appid, $secret) { $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret; $res = $this->curl($url); return json_decode($res, true); } }