Jump to the designated WeChat scan code to follow the webpage (with code)

云罗郡主
Release: 2018-10-12 14:37:54
forward
8182 people have browsed it

The content of this article is about jumping to the designated WeChat scan code to follow the webpage (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Jump to the designated WeChat scan code to follow the web page, easily add friends and follow the public account

Sample code

The following code is only a pseudo code for demonstration. The interface needs to be implemented by the user.

Address Book Interface

Enterprise WeChat opens two permissions, the reading and editing permissions of the address book. The following is an example of adding a department (other interfaces are similar):

Step one: Get the access_token of the address book application

public function getAccessToken($corpid,$secret) { //TODO: access_token should be stored and updated globally, the following code is written to the file As an example //TODO: The access_token of each application should be stored independently. Here, secret is used as the identifier to distinguish the application. $path = "/cache/$secret.php"; $data = json_decode (get_php_file ($path)); if ($data->expire_time < time()) { $url = "https://qyapi.weixin.qq.com/cgi-bin/gettokencorpid=$corpid&corpsecret=$secret"; $res = json_decode(http_get( $url)["content"]); $access_token = $res->access_token; if ($access_token) { $data->expire_time = time() 7000; $data->access_token = $access_token; set_php_file( $path, json_encode($data)); } } else { $access_token = $data->access_token; } return $access_token; }

Step 2: Encapsulate the data package and send it to the enterprise WeChat backend

$info = $array("name" => "Add department name", "parentid" => 1, "order" => 10, "id" => 12); // TODO: Pass in your corporate corpid and the secret information of the address book application here $txl_access_token = getAccessToken("corpid","txl_secret"); print(http_post("https://qyapi.weixin.qq.com/cgi- bin/department/createac

The above is the complete introduction to jump to the WeChat designated scan code to follow the webpage (with code), if you want to know more aboutWeChat development graphic tutorial, please pay attention to the PHP Chinese website.


The above is the detailed content of Jump to the designated WeChat scan code to follow the webpage (with code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:2cto.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template