# # WeChat has become an indispensable app in our lives. With the help of WeChat platform, WeChat official account has also become a mainstream online and offline interactive marketing method. The development of public accounts has also become a front-end er One of the indispensable skills. Public accounts are mainly divided into two types: subscription accounts and service accounts. The former mainly pushes messages and provides communication for media and individuals, while the latter can provide services to users within WeChat through WeChat authorization. , for enterprises Provide business services and powerful user management capabilities. The former basically does not involve the front end, so the latter is what we mainly introduce today. Register an accountThis step is the first step. You need to apply for a service account first. I won’t go into details about this step. You can go directly to the official website to apply for an account. There will be Some review processes will not be discussed in detail here. During this waiting process, if you want to start development immediately, you can go to the WeChat public account to test the platform Go apply for a test number. Of course, if you just want to experience it, you can also apply for a test account to experience it. Configuration environmentBefore development, we must first make preparations, including the configuration of the WeChat public account and the configuration of the local development environment. Because it is inconvenient to use the company’s account, all of the following The picture example comes from the WeChat test public account. The test accounts are all easily found on one page, so I won’t go into details. Let’s talk about the official configurationPublic account configurationRelated learning recommendations: WeChat public account development tutorial

1. Before the WeChat official account requests user web page authorization, developers need to go to the "Development - Interface Permissions - Web Services - Web Accounts - Web Page Authorization to Obtain User Basic Information" configuration option on the official website of the public platform. , modify the authorization callback domain name. Please note that the domain name (which is a string) is filled in here, not the URL, so please do not add protocol headers such as http://;2. The authorization callback domain name configuration specification is the full domain name, such as web page authorization is required The domain name is: www.qq.com. After configuration, the pages under this domain name http://www.qq.com… and www.qq.com/login.html can all perform OAuth2.0 authentication. However, pay.qq.com, music.qq.com, and qq.com cannot perform OAuth2.0 authentication;
3. If the official account login is authorized to a third-party developer for management, you do not need to make any settings. A third party can replace the official account to achieve web page authorization. If you need to use some functions of jsapi such as WeChat payment, sharing, etc., you need to configure the JS interface security domain name.

Log in to the WeChat public platform and enter the "Function Settings" of "Public Account Settings" to fill in the "JS Interface Security Domain Name" .Local environment configurationIn the test official account, both the IP and domain name addresses can be authorized successfully, but in the official official account, if you want to implement local testing, you need an external network To be able to access the local intranet, we need to achieve intranet penetration, that is, we can map the intranet server to the external network for others to access. There are also many Tools such as
- natapp
- Peanut Shell
- utools I use utools, a tool set, so the following uses utools as an example
-
##Click to download and install. Then click to configure your local service and external network to start using it, so that you can access it directly using only the external network address. WeChat public account debugging environment
Callback authorization requires WeChat environment, so we cannot Debugging in chrome undoubtedly makes it more difficult for us to find nasty bugs. So we need an artifact for WeChat development, WeChat development tool When doing this step, you need to pay attention
Bind to the developer of the official accountDevelopment configuration
1. Business development
Write our Business code. This is not much different from an ordinary page, so I won’t go into details
2. Authorization
WeChat web page authorization is mainly divided into two types
1. Web page authorization initiated with snsapi_base as the scope is used to obtain the openid of the user who enters the page, and is authorized silently and automatically jumps to the callback page. What the user perceives is that he directly enters the callback page (often a business page)
2. The web page authorization initiated with snsapi_userinfo as the scope is used to obtain the user's basic information. However, this kind of authorization requires the user to manually agree, and since the user has agreed, there is no need to pay attention, and the user's basic information can be obtained after authorization.
3. The "Obtain User Basic Information Interface" in the user management interface can obtain the user's basic information based on the user's OpenID only after the user interacts with the official account or pushes the following event. This interface, including other WeChat interfaces, requires the user (i.e. openid) to follow the official account before it can be called successfully.
In addition to using snsapi_base
to be able to authorize silently, there are others that can also be authorized silently
For users who have followed the official account, if When a user enters the official account's web authorization page from the official account's session or custom menu, even if the scope is snsapi_userinfo, the authorization is silent and the user is unaware.
Steps
Specifically, the web page authorization process is divided into four steps:
1. Guide the user to enter the authorization page to agree to the authorization and obtain the code
2. Exchange the webpage authorization access_token through code (different from the access_token in basic support)
3. If necessary, developers can refresh the webpage authorization access_token to avoid expiration
4. Through the webpage Authorize access_token and openid to obtain basic user information (supports UnionID mechanism)
What the front end needs to do
1. Guide the user to enter the authorization page to agree to the authorization and obtain the codehttps://open. weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
This is the link to the authorization page. Replace appId, redirect_uri, and scope with what you need. Scope is The two different authorizations mentioned above. !!! It should be noted that because the state uses Hash routing, there is #, and the front-end part of the framework defaults to hash routing, which will cause conflicts, so it needs to be encoded
If the user agrees Authorization, the page will jump to redirect_uri/?code=CODE&state=STATE.
The picture below shows the authorization page when the scope is equal to snsapi_userinfo:

At this time, we only need to pass our code to the background, and the next few steps will follow. No front-end required.
JSSDK usage steps
Sometimes we also need to use SSDK, so we need to configure it
Bind domain name
That is the JS above Interface security domain name setting,
Introduce JS files
Introduce the following JS files on the page that needs to call the JS interface, (supports https): res.wx.qq.com/open/js/jwe …
If you need to further improve service stability, when the above resources are inaccessible, you can visit: res2.wx.qq.com/open/js/jwe… (supports https).
Inject permission verification configuration through the config interface
wx.config({ debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: '', // 必填,公众号的唯一标识 timestamp: , // 必填,生成签名的时间戳 nonceStr: '', // 必填,生成签名的随机串 signature: '',// 必填,签名 jsApiList: [] // 必填,需要使用的JS接口列表});复制代码
jsApiList To write the functions you need, you can see the official JS interface list,appId, timestamp,nonceStr, signature
then Need your backend partner to get back to you.
It should be noted that:
All pages that need to use JS-SDK must first inject configuration information, otherwise it will not be called (the same URL only needs to be called once, for changing URLs The SPA web app can be called every time the URL changes. Currently, the Android WeChat client does not support the new H5 feature of pushState, so using pushState to implement the web app page will cause the signature to fail. This problem will be solved in Android 6.2 repair).
Related learning recommendations: js video tutorial
Calling the WeChat interface
Then just call the WeChat interface in ready. The following takes the detection of js interface as an example.
wx.ready(function(){ // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。 wx.checkJsApi({ jsApiList: ['chooseImage'], // 需要检测的JS接口列表 success: function(res) { // 以键值对的形式返回,可用的api值true,不可用为false // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"} } }); });复制代码
In fact, as long as the front-end is authorized, the subsequent jssdk will be very simple.
Related learning recommendations: WeChat Mini Program Development
The above is the detailed content of Getting Started with Official Accounts. For more information, please follow other related articles on the PHP Chinese website!

在公众平台的注册页面选择账号类型后,填写相关信息即可注册。教程适用型号:联想AIO520C系统:Windows10专业版解析1首先进入微信公众平台首页中,点击顶部的立即注册。2进入注册页面中,选择账号类型。3按要求填写相关信息后,点击页面下方的注册即可。补充:微信公众号的类型有几种1微信公众号的类型有:公众平台服务号、公众平台订阅号、小程序、企业微信四种。总结/注意事项企业微信就是原先的企业号。

微信服务号和公众号区别:1、微信服务号是面向具备一定资质的有实体机构的企业或个人提供的账号形式,注册公众号是免费的,无需支付费用;2、微信服务号相对而言更加强大,功能和权限更全面,而公众号的功能相对较为简单,主要是提供信息传达和互动交流;3、微信服务号可以向用户发送模板消息、群发消息、客服消息等,而公众号只能通过群发消息的方式推送内容;4、微信服务号具备更丰富的功能等等。

如何使用PHP开发公众号的二维码生成功能当今社交媒体的盛行使得公众号成为企业与用户互动的重要渠道之一。为了吸引更多用户关注公众号,企业常常会使用二维码来方便用户扫码关注。本文将介绍如何使用PHP开发公众号的二维码生成功能,并提供具体的代码示例。获取二维码生成地址在使用PHP开发公众号的二维码生成功能之前,我们首先需要获取二维码生成地址。可以通过微信公众平台提

公众号每天不是只能发一篇文章,每次最多可以发表八篇文章,多篇文章的发布方法:1、点击左侧的“素材管理”,再点击“新建图文素材”开始编辑第一篇文章;2、编辑完第一篇文章之后,点击左侧第一篇文章下面的+号,点击“图文消息”即可编辑第二篇文章;3、做完多图文后,点击“保管并群发”即可完成多篇文章的发布。

让我们继续来聊暴雪国服回归!很多粉丝都在说,小探你都连续招3天了,怎么还招?我只能这么说,这一次国服在4~5月回归是铁板钉钉的,真的不能再真,小探起码确认了5个以上的消息源,竞核说的就是真的!还有朋友问,上次36氪就放空炮了,让我们凭啥相信竞核的稿子,他们不都是财经大媒体吗?(竞核是钛媒体的游戏厂牌)那我们回过头来看看36氪的稿子,看看人人家是怎么说的:游戏重新上线,可能要半年。现在我们来算算时间,去年12月到今年5月,可不就是半年?这怎么能说人家吹牛呢?人家36氪是纳斯达克上市的财经大媒体,不

1、首先点击【通讯录】——选择【公众号】。2、选择其中的公众号,找到你想要阅读的文章,点击进去阅读。3、阅读过程来了需要回复的信息时,点击右上角的【三点】图标。4、然后点击【在聊天中置顶】。5、然后我们返回去聊天,发信息,我们回复完消息,再点击聊天界面最上面的【正在浏览】就能回到刚才阅读的文章了。

如何使用PHP开发公众号的关键词回复功能随着社交媒体的快速发展,微信公众号已成为企业、机构和个人传播信息的重要渠道之一。为了提高用户体验,并能够及时回复用户的消息,开发公众号的关键词回复功能是非常重要的。本文将介绍如何使用PHP来开发公众号的关键词回复功能,并提供具体的代码示例。一、创建一个公众号首先,我们需要在微信公众平台上创建一个公众号。注册并绑定公众号

公众号不可以转移主体,因为根据微信公众号的规定,公众号目前是不允许直接转移主体的。公众号的主体一旦注册后,其所有权和管理权通常是固定的,不可随意更改。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Chinese version
Chinese version, very easy to use

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version
Visual web development tools
