/**
* 获取code
* @return code code作为换取access_token的票据,每次用户授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期
*/
public function actionIndex(){
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$this->appid."&secret=".$this->secret."&code=".$_GET['code']."&grant_type=authorization_code";
$token = file_get_contents($url);
$token = json_decode($token,true);
$token["access_token"];
$user_url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$token['access_token']."&openid=".$token["openid"]."&lang=zh_CN";
$userinfo = file_get_contents($user_url);
$arr = json_decode($userinfo,true);
$openid = $arr['openid'];
$unionid = $arr['unionid'];/*该字段必须在微信开发平台(https://open.weixin.qq.com/)进行关联*/
}