1.我们首先在公众测试号那配置授权回调域名(注意不加http和Https):
2.获取code
在控制器写入以下代码:
public function index(){
$appid="wx4ff531ee8a470861";
$rediret_url=urlencode('http://wyzdjg.top/vote/index.php/home/index/getcode');
// $rediret_url=urlencode('http://www.baidu.com');
$url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$rediret_url&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
header("location:".$url);
}
public function getcode(){
$code=$_GET['code'];
$json=$this->access_token($code);
// echo $json;
$arr=json_decode($json,true);
$arr=array_