本地测试环境可用。省去了后端返回假数据。
服务器上可用切换回post方法。
public function getsessionkey()
{
$code = input('post.code','');
if (!$code) {
exit(json_encode(array('code'=>404,'msg'=>'error','data'=>"非法操作!")));
}
$url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$this->xcx_appid.'&secret='.$this->xcx_appsecret.'&js_code='.$code.'&grant_type=authorization_code';
$result = $this->httpGet($url, "GET");
$result = json_decode($result, true);
return DataReturn('success', 1, $result);
}
public function httpGet($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}