uniapp mobile app integrated WeChat login (front end)

Statement of needs:

The existing WeChat applet project and mobile app project need to implement the WeChat cash withdrawal function, and WeChat cash withdrawal requires openid, so the actual is to obtain the WeChat openid, what is openid, that is, a binding relationship between the user and the application, so the applet and app OpenID can be obtained through WeChat authorized login.
Because the mini program authorization login has already been realized, now only need to realize app WeChat login
official api: WeChat login

Implementation steps:

1. OAuth (login authentication)

Open the manifest.json file of the project, and under "OAuth (login authentication)" of the "App module configuration" item, check "WeChat login"
insert image description here

2. Call uni.login to get the code

 uni.login({
    
    
   "provider": "weixin",
    "onlyAuthorize": true, // 微信登录仅请求授权认证
    success: function (loginRes) {
    
    
    	//loginRes.code为返回的code,通过code调用后端getOpenId接口即可返回openid,前端自行存储即可
        self.getOpenId(loginRes)
    },
    fail: function (err) {
    
    
        setTimeout(() => {
    
    
            uni.showToast({
    
    
                title: '微信绑定失败',
                icon: 'none',
                duration: 3000
            });
        },500)
    }
});

3. Authorized login effect

After obtaining the openId through WeChat authorized login, you can call the back-end cash withdrawal interface where you need to withdraw cash, and perform WeChat cash withdrawal
insert image description here

Notice!!!

1. App development and debugging must use custom dock debugging (h5, emulator, real device will not work)
2. Apple login is a newly added function of **iOS13**, when your application uses a third-party login such as WeChat login , and also need to integrate Apple login, otherwise the submission of AppStore review will be rejected, so the ios app also needs to authorize Apple login, and at the same time need to go to the Apple Developer Center to configure the application
insert image description here
. If the ios app does not need WeChat login, no new code is required. Consistent with the authorization method of the Android version

Guess you like

Origin blog.csdn.net/weixin_45059911/article/details/131642751
Recommended