欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

laravel6 微信公眾號獲取用戶信息 - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設/小程序開發(fā)/軟件開發(fā)

知識

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價值,我們在追求其視覺表現(xiàn)的同時,更側(cè)重于功能的便捷,營銷的便利,運營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!

您當前位置>首頁 » 新聞資訊 » 公眾號相關(guān) >

laravel6 微信公眾號獲取用戶信息

發(fā)表時間:2020-10-18

發(fā)布人:葵宇科技

瀏覽次數(shù):66

創(chuàng)建控制器

php artisan make:controller WeChatController

獲取code和token

 public function wxcode()
    {
        //一定要按照參數(shù)的順序進行排列,否則接口將無法訪問
        $params = http_build_query([
            'appid' => '微信公眾號的appid',
            'redirect_uri' => '自己的域名/wxtoken',
            'response_type' => 'code',
            'scope' => 'snsapi_userinfo'
        ]);
        $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?'.$params .'#wechat_redirect';
        return redirect($url);
    }


    public function wxtoken(Request $request)
    {
      $code = $request->input('code');
      $params = http_build_query([
        'appid' => '微信公眾號的appid',
        'secret'=> '微信公眾號的appsecret',
        'code' => $code,
        'grant_type' => 'authorization_code'
      ]);
      $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?'.$params;
      $result = json_decode(file_get_contents($url));
      // dd($result);
      $params = http_build_query([
        'access_token' => $result->access_token,
        'openid' => $result->openid,
        'lang' => 'zh_CN',
      ]);
      $url = 'https://api.weixin.qq.com/sns/userinfo?'.$params;
      $UserInfo = json_decode(file_get_contents($url));
      dd($UserInfo);
    }

配置路由

Route::get('wxcode','WeChatController@wxcode');
Route::get('wxtoken','WeChatController@wxtoken');

在微信開發(fā)者工具上訪問 域名/wxcode 就可以獲取到用戶信息了

微信測試號地址

http://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index

相關(guān)案例查看更多