At present, personal subject apps on wechat open platform do not support wechat login, so how do individual developers solve the problem of wechat login? At present, there is an alternative plan to use wechat mini program as a medium to achieve the purpose of wechat login.
Wechat applet login does not require enterprise qualification, and the following information will be returned after login
- The user uniquely identifies open_id
- Head portrait
- nickname
== And wechat applet can be opened by APP, and data can be returned after operation. = =
Therefore, the current idea is to realize wechat login through APP jump small program login and then return
Implementation prerequisites
- Wechat open platform account (human)
- Create APP on development platform and approve it
- A wechat mini program has been launched
- Bind the wechat applet in the open platform
- APP is associated with applets
Of course, there is no online micro channel small program can also, small program ID can, but only for testing
Take Android APP as an example, after the integration of wechat SDK initialization, set the original ID of the small program to jump the small program, and parameters can be passed to the small program
String appId = "..."; AppId final IWXAPI API = wxapiFactory.createWxapi (this, AppId); api.registerApp(appId); findViewById(R.id.wx_login).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
req.userName = "gh_f1312c106dff"; // Fill in the original id of the applet req.path ="pages/index/index? appLogin=1"; // Pull up the parameter path of the applet page, do not fill in the default pull up the applet home page, for small games, you can only pass in the query part, to achieve the parameter effect, such as: pass"? foo=bar". req.miniprogramType = WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_TEST; SendReq (req); sendReq(req); sendReq(req); }});Copy the code
The applets will receive arguments in onLoad and then call wx.login to get js_code and open_id from js_code
onLoad(options) {
if(options.appLogin){wx.login({success: res => {// send res.code to the backend for openId, sessionKey, unionId}})}},Copy the code
Button open-type=”getUserInfo” can be used to pop up the login application to obtain user information, and then return to the APP client
Wechat related documents
Developers.weixin.qq.com/miniprogram… Developers.weixin.qq.com/doc/oplatfo…
By the way, I will post a public account. If you are not interested, you can skip it
“IT Independent Developer” helps programmers to expand their thinking ability in product, operation and design, develop independent products, and strive to become freelancers and achieve wealth freedom