国产三级农村妇女在线,国产精品毛片a∨一区二区三区,国产乱子伦视频大全,国产精品色拉拉,国产欧美日韩一区二区三区,

首頁(yè) > 技術(shù) > cms教程

PbootCMS對(duì)接微信開(kāi)放平臺(tái)掃碼登錄

小編 cms教程 2023-03-06 21:15:32

1676007054206162.png

<?php

/**

 * 微信公眾號(hào)配置

 * ============================================================================

 * 版權(quán)所有  云管家網(wǎng)絡(luò)科技有限公司

 * 網(wǎng)站地址: https://www.kaifacn.com

 * ============================================================================

 */

namespace coreasic;

use coreasicConfig;


class Wechat

{

    protected $appid;

    protected $secret;


    public function __construct()

    {

        // 配置參數(shù)

        $this->appid = Config::get('weixin_appid');

        $this->secret = Config::get('weixin_secret');

    }


    // 獲取登錄二維碼

    public function getqrcode()

    {

        // 回調(diào)地址

        $redirect_uri= get_http_url().Url::home('Member/login');

        // 該回調(diào)需要url編碼

        $redirect_uri=urlencode($redirect_uri);

        $url = "https://open.weixin.qq.com/connect/qrconnect?appid=".$this->appid."&redirect_uri=".$redirect_uri."&response_type=code&scope=snsapi_login&state=".session('access_token')."#wechat_redirect";

        $result = get_url($url);

        // 修改二維碼路徑

        $result = str_replace("/connect/qrcode/", "https://open.weixin.qq.com/connect/qrcode/", $result);

        // 簡(jiǎn)單優(yōu)化一下頁(yè)面樣式

        $result = str_replace('<body>','<style>.impowerBox .qrcode{width: 220px;margin-top:0px;}.impowerBox .icon38_msg {width: 30px;height: 30px;margin-left: 27px;}</style><body>',$result);

        $result = str_replace('<div>微信登錄</div>','',$result);

        $result = str_replace('<p>“CMS開(kāi)發(fā)網(wǎng)”</p>','',$result);

        $result = str_replace('<h4>掃描成功</h4>','<h4>掃描成功,請(qǐng)點(diǎn)擊授權(quán)!</h4>',$result);

        $result = str_replace('<p>在微信中輕觸允許即可登錄</p>','',$result);

        $result = str_replace('<p>你可再次掃描登錄,或關(guān)閉窗口</p>','',$result);

        $result = str_replace('<p>使用微信掃一掃登錄</p>','<div><i></i>使用微信掃一掃登錄</div>',$result);


        echo $result;

    }


    // 獲取登錄授權(quán)信息

    public function getWxUser()

    {

        $code = get('code');

        $state = get('state');

        if ($code && $state && session('access_token') == $state)

        {

            $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$this->appid."&secret=".$this->secret."&code=".$code."&grant_type=authorization_code";

            $jsonResult = file_get_contents($url);

            $result = json_decode($jsonResult, true);

            $data = $this->getAuthUserInfo($result['access_token'],$result['openid']);

            return $data;

        }

        location(Url::home('member/login'));

    }


    // 獲取用戶信息

    private function getAuthUserInfo($token, $openid)

    {

        $url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$token."&openid=".$openid."&lang=zh_CN";

        $result = json_decode(get_url($url));

        if (isset($result->errcode) && $result->errcode)

        {

            location(Url::home('member/login'));

        }

        return $result;

    }

}

放在/core/basic里面,需自行處理登錄業(yè)務(wù)邏輯,本教程使用微信開(kāi)放平臺(tái)配置

TAg

加載中~

本網(wǎng)站LOGO受版權(quán)及商標(biāo)保護(hù),版權(quán)登記號(hào):國(guó)作登字-2022-F-10126915,未經(jīng)湖南木星科技官方許可,嚴(yán)禁使用。
Copyright ? 2012-2022 湖南木星科技有限公司(木星網(wǎng))版權(quán)所有
轉(zhuǎn)載內(nèi)容版權(quán)歸作者及來(lái)源網(wǎng)站所有,本站原創(chuàng)內(nèi)容轉(zhuǎn)載請(qǐng)注明來(lái)源,商業(yè)媒體及紙媒請(qǐng)先聯(lián)系:aishangyiwan@126.com

工信部備案號(hào):湘ICP備19012813號(hào)-5