微信小程序根据CODE获取用户open_id
public function get_user_opendid() {
$code = $this->request->param('code');
// 构造接口url
$app_id = '1111111111111111111';
$secret = '4444444444444444444444';
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$app_id}&secret={$secret}&js_code={$code}&grant_type=authorization_code";
//初始化curl
$ch = curl_init();
$curlVersion = curl_version();
//设置参数
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//运行curl,结果以json形式返回
$res = curl_exec($ch);
$disposeData = json_decode($res,true);
}