前提,在微信开放平台绑定微信公众号,然后登录后用openid换取unionid
$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . C(APPID) . "&secret=" . C(APPSECRET) . "&code=" . $code . "&grant_type=authorization_code";
$res = $this->https_request($url);
$res = json_decode($res, true);
$openid = $res["openid"];
$url0="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . C(APPID) . "&secret=" . C(APPSECRET) ;
$res0 = $this->https_request($url0);
$res0 = json_decode($res0, true);
$access_token=$res0["access_token"];
$url1="https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $openid . "&lang=zh_CN";
$res1 = $this->https_request($url1);
$res1 = json_decode($res1, true);
$unionid=$res1["unionid"];