/**
* 獲取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/)進行關聯*/
}