国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
1. WeChat public platform configuration
1. Obtain appid, appsecret, add whitelist
2. Add web page authorization
2. PHP backend implementation
1. Obtain global token
2. Obtaining the openid of the public account associated with the user
3. Obtain user information
3. Use
Home WeChat Applet WeChat Development The code is still easy to use, and you can determine whether the user has followed the official account in just a few steps.

The code is still easy to use, and you can determine whether the user has followed the official account in just a few steps.

Jul 25, 2018 pm 03:04 PM
javascript php No public focus on WeChat

Many of today’s activities guide users to follow public accounts in order to participate in activities. How to judge whether users have followed public accounts is actually very simple. Follow this article and you will no longer have to worry. The php code in this article is very simple. Explained in detail.

1. WeChat public platform configuration

1. Obtain appid, appsecret, add whitelist

Log in to WeChat public platform and enter basic configuration. Two parameters need to be used in development, appId and appSecret (appSecret is only displayed once and needs to be saved, otherwise it needs to be reset and obtained).
You need to add an IP whitelist when obtaining access_token.
The code is still easy to use, and you can determine whether the user has followed the official account in just a few steps.

Click to view

The code is still easy to use, and you can determine whether the user has followed the official account in just a few steps.
Click to modify
The code is still easy to use, and you can determine whether the user has followed the official account in just a few steps.

2. Add web page authorization

Enter the official account settings=》Function settings=》Web page authorized domain name
The code is still easy to use, and you can determine whether the user has followed the official account in just a few steps.Click settings, enter the domain name of the authorization callback page in the input box, refer to point 1 (only one can be filled in), download the txt in point 3 Documents are uploaded to the root directory of the server.
The code is still easy to use, and you can determine whether the user has followed the official account in just a few steps.

2. PHP backend implementation

1. Obtain global token

This token is valid for 2 hours and can be temporarily stored. It is required after expiration Reacquire.
PS: The project must use the same interface, otherwise it will easily lead to expiration due to mutual brushing.

public static function getToken($appid, $appsecret){
    $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
    return Curl::callWebServer($url);
}

正確返回結(jié)果:
    {
        "access_token": "ACCESS_TOKEN",
        "expires_in": 7200
    }
    返回結(jié)果參數(shù)說明:
    參數(shù)              說明
    access_token      獲取到的全局token
    expires_in        憑證有效時(shí)間,單位:秒
    
錯(cuò)誤返回結(jié)果:
    {"errcode": 40013, "errmsg": "invalid appid"}
    返回結(jié)果參數(shù)說明:
    返回碼    說明
    -1       系統(tǒng)繁忙,此時(shí)請開發(fā)者稍候再試
    0        請求成功
    40001    AppSecret錯(cuò)誤或者AppSecret不屬于這個(gè)公眾號,請開發(fā)者確認(rèn)        AppSecret的正確性
    40002    請確保grant_type字段值為client_credential
    40164    調(diào)用接口的IP地址不在白名單中,請?jiān)诮涌贗P白名單中進(jìn)行設(shè)置。(小程序及小游戲調(diào)用不要求IP地址在白名單內(nèi)。)

2. Obtaining the openid of the public account associated with the user

is a two-step process. First, obtain the user's authorization code for the public account, and then use this code to obtain the temporary access_token and openid.

Get user authorization code

public static function getCode($appId, $redirect_uri, $state=1, $scope='snsapi_base', $response_type='code'){
    $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appId.'&redirect_uri='.$redirect_uri.'&response_type='.$response_type.'&scope='.$scope.'&state='.$state.'#wechat_redirect';
    header('Location: '.$url, true, 301);
}

正確返回結(jié)果:
    返回code碼,并且跳轉(zhuǎn)回調(diào)頁面$redirect_uri
    
錯(cuò)誤返回結(jié)果:
    {"errcode": 10003, "errmsg": "redirect_uri域名與后臺(tái)配置不一致"}
    返回結(jié)果參數(shù)說明:
    返回碼    說明
    10003    redirect_uri域名與后臺(tái)配置不一致
    10004    此公眾號被封禁
    10005    此公眾號并沒有這些scope的權(quán)限
    10006    必須關(guān)注此測試號
    10009    操作太頻繁了,請稍后重試
    10010    scope不能為空
    10011    redirect_uri不能為空
    10012    appid不能為空
    10013    state不能為空
    10015    公眾號未授權(quán)第三方平臺(tái),請檢查授權(quán)狀態(tài)
    10016    不支持微信開放平臺(tái)的Appid,請使用公眾號Appid

The code obtained through getCode is exchanged for the access_token and openid authorized by the webpage

public static function getAccessToken($code, $appid, $appsecret, $grant_type='authorization_code'){
    $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type='.$grant_type.'';
    return Curl::callWebServer($url);
}
   
正確返回結(jié)果:
    { 
        "access_token": "ACCESS_TOKEN",
        "expires_in": 7200,
        "refresh_token": "REFRESH_TOKEN",
        "openid": "OPENID",
        "scope": "SCOPE"
    }
    返回參數(shù)說明
    參數(shù)            描述
    access_token    網(wǎng)頁授權(quán)接口調(diào)用憑證,注意:此access_token與基礎(chǔ)支持的access_token不同
    expires_in    access_token接口調(diào)用憑證超時(shí)時(shí)間,單位(秒)
    refresh_token    用戶刷新access_token
    openid    用戶唯一標(biāo)識,請注意,在未關(guān)注公眾號時(shí),用戶訪問公眾號的網(wǎng)頁,也會(huì)產(chǎn)生一個(gè)用戶和公眾號唯一的OpenID
    scope    用戶授權(quán)的作用域,使用逗號(,)分隔
    
錯(cuò)誤返回結(jié)果:
    {"errcode":40029, "errmsg":"invalid code"}

3. Obtain user information

Use the first Use the openId obtained in step 2 and the token obtained in step 1 to obtain user information

public static function getUserInfo($openId, $token){
    $url = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token='.$token.'&openid='.$openId.'&lang=zh_CN';
    return Curl::callWebServer($queryUrl, '', 'GET');
}
正確返回結(jié)果:
    {
        "subscribe": 1, 
        "openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M", 
        "nickname": "Band", 
        "sex": 1, 
        "language": "zh_CN", 
        "city": "廣州", 
        "province": "廣東", 
        "country": "中國", 
        "headimgurl":"http://thirdwx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0",
        "subscribe_time": 1382694957,
        "unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL"
        "remark": "",
        "groupid": 0,
        "tagid_list":[128,2],
        "subscribe_scene": "ADD_SCENE_QR_CODE",
        "qr_scene": 98765,
        "qr_scene_str": ""
    }
    返回參數(shù)說明:
        參數(shù)            說明
        subscribe       用戶是否訂閱該公眾號標(biāo)識,值為0時(shí),代表此用戶沒有關(guān)注該公眾號,拉取不到其余信息。
        openid          用戶的標(biāo)識,對當(dāng)前公眾號唯一
        nickname        用戶的昵稱
        sex             用戶的性別,值為1時(shí)是男性,值為2時(shí)是女性,值為0時(shí)是未知
        city            用戶所在城市
        country         用戶所在國家
        province        用戶所在省份
        language        用戶的語言,簡體中文為zh_CN
        headimgurl      用戶頭像,最后一個(gè)數(shù)值代表正方形頭像大小(有0、46、64、96、132數(shù)值可選,0代表640*640正方形頭像),用戶沒有頭像時(shí)該項(xiàng)為空。若用戶更換頭像,原有頭像URL將失效。
        subscribe_time  用戶關(guān)注時(shí)間,為時(shí)間戳。如果用戶曾多次關(guān)注,則取最后關(guān)注時(shí)間
        unionid         只有在用戶將公眾號綁定到微信開放平臺(tái)帳號后,才會(huì)出現(xiàn)該字段。
        remark          公眾號運(yùn)營者對粉絲的備注,公眾號運(yùn)營者可在微信公眾平臺(tái)用戶管理界面對粉絲添加備注
        groupid         用戶所在的分組ID(兼容舊的用戶分組接口)
        tagid_list      用戶被打上的標(biāo)簽ID列表
        subscribe_scene 返回用戶關(guān)注的渠道來源,ADD_SCENE_SEARCH 公眾號搜索,ADD_SCENE_ACCOUNT_MIGRATION 公眾號遷移,ADD_SCENE_PROFILE_CARD 名片分享,ADD_SCENE_QR_CODE 掃描二維碼,ADD_SCENEPROFILE LINK 圖文頁內(nèi)名稱點(diǎn)擊,ADD_SCENE_PROFILE_ITEM 圖文頁右上角菜單,ADD_SCENE_PAID 支付后關(guān)注,ADD_SCENE_OTHERS 其他
        qr_scene        二維碼掃碼場景(開發(fā)者自定義)
        qr_scene_str    二維碼掃碼場景描述(開發(fā)者自定義)

錯(cuò)誤結(jié)果:
    {"errcode":40013,"errmsg":"invalid appid"}

3. Use

to determine whether you have followed it. Here is the entrance:

public function isConcern($appId, $appSecret) {
    $param = ''; // 如果有參數(shù)
    $this->getCode($appId, U('callback', 'param='.$param), 1 ,'snsapi_base');
}

Callback after authorization

public function callback(){
    $isconcern = 0;
    $code = $this->_get('code');
    $param = $this->_get('param');
    $appId = C('appId'); // config中配置
    $appSecret = C('appSecret');
    $accessTokenInfo = $this->getAccessToken($code, $appId, $appSecret);
    $openId = $accessTokenInfo['openid'];
    $accessToken = $accessTokenInfo['access_token'];
    $token = $this->getToken($appId, $appSecret);
    $userInfo = $this->getUserInfo($openId, $token['access_token']);
    if($userInfo['subscribe'] == 1){
        $this->assign('userInfo', $userInfo);
        $isconcern = 1; // 已關(guān)注
    } else {
        $isconcern = 0; // 未關(guān)注
    }
    $this->assign('openid', $openId);
    $this->display('page');
}

At this time, userInfo and isconcern can be obtained on the page. When isconcern is 1, it means that the official account has been followed, otherwise it has not been followed.

Related recommendations:

WeChat public account development WeChat public account determines whether the user has paid attention to php code analysis

PHP determines the character type php Determine whether the user is following the WeChat public account

Video: Following and canceling the public account-0 Introduction to basic WeChat development

The above is the detailed content of The code is still easy to use, and you can determine whether the user has followed the official account in just a few steps.. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to get the current session ID in PHP? How to get the current session ID in PHP? Jul 13, 2025 am 03:02 AM

The method to get the current session ID in PHP is to use the session_id() function, but you must call session_start() to successfully obtain it. 1. Call session_start() to start the session; 2. Use session_id() to read the session ID and output a string similar to abc123def456ghi789; 3. If the return is empty, check whether session_start() is missing, whether the user accesses for the first time, or whether the session is destroyed; 4. The session ID can be used for logging, security verification and cross-request communication, but security needs to be paid attention to. Make sure that the session is correctly enabled and the ID can be obtained successfully.

PHP get substring from a string PHP get substring from a string Jul 13, 2025 am 02:59 AM

To extract substrings from PHP strings, you can use the substr() function, which is syntax substr(string$string,int$start,?int$length=null), and if the length is not specified, it will be intercepted to the end; when processing multi-byte characters such as Chinese, you should use the mb_substr() function to avoid garbled code; if you need to intercept the string according to a specific separator, you can use exploit() or combine strpos() and substr() to implement it, such as extracting file name extensions or domain names.

How do you perform unit testing for php code? How do you perform unit testing for php code? Jul 13, 2025 am 02:54 AM

UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

How to split a string into an array in PHP How to split a string into an array in PHP Jul 13, 2025 am 02:59 AM

In PHP, the most common method is to split the string into an array using the exploit() function. This function divides the string into multiple parts through the specified delimiter and returns an array. The syntax is exploit(separator, string, limit), where separator is the separator, string is the original string, and limit is an optional parameter to control the maximum number of segments. For example $str="apple,banana,orange";$arr=explode(",",$str); The result is ["apple","bana

JavaScript Data Types: Primitive vs Reference JavaScript Data Types: Primitive vs Reference Jul 13, 2025 am 02:43 AM

JavaScript data types are divided into primitive types and reference types. Primitive types include string, number, boolean, null, undefined, and symbol. The values are immutable and copies are copied when assigning values, so they do not affect each other; reference types such as objects, arrays and functions store memory addresses, and variables pointing to the same object will affect each other. Typeof and instanceof can be used to determine types, but pay attention to the historical issues of typeofnull. Understanding these two types of differences can help write more stable and reliable code.

Using std::chrono in C Using std::chrono in C Jul 15, 2025 am 01:30 AM

std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

How to pass a session variable to another page in PHP? How to pass a session variable to another page in PHP? Jul 13, 2025 am 02:39 AM

In PHP, to pass a session variable to another page, the key is to start the session correctly and use the same $_SESSION key name. 1. Before using session variables for each page, it must be called session_start() and placed in the front of the script; 2. Set session variables such as $_SESSION['username']='JohnDoe' on the first page; 3. After calling session_start() on another page, access the variables through the same key name; 4. Make sure that session_start() is called on each page, avoid outputting content in advance, and check that the session storage path on the server is writable; 5. Use ses

How does PHP handle Environment Variables? How does PHP handle Environment Variables? Jul 14, 2025 am 03:01 AM

ToaccessenvironmentvariablesinPHP,usegetenv()orthe$_ENVsuperglobal.1.getenv('VAR_NAME')retrievesaspecificvariable.2.$_ENV['VAR_NAME']accessesvariablesifvariables_orderinphp.iniincludes"E".SetvariablesviaCLIwithVAR=valuephpscript.php,inApach

See all articles