WeChat Mini Programs gets code

I just started to learn the development of WeChat Mini Programs. When I get token, I need to get the code first.

in the video tutorial I watched, the teacher used a small code acquisition tool, but I couldn"t find the tool

find the example code of Wechat"s developer document for yourself

//app.js
App({
  onLaunch: function() {
    wx.login({
      success: function(res) {
        if (res.code) {
          //
          wx.request({
            url: "https://test.com/onLogin",
            data: {
              code: res.code
            }
          })
        } else {
          console.log("" + res.errMsg)
        }
      }
    });
  }
})

does it not need to pass parameters such as appId, and how to pass them in? The first time I use it, I don"t have any ideas. Please give me a complete example. Thank you
why not write it in a form similar to the https://api.weixin.qq.com/sns.
URL, and get the

in this form.
Mar.14,2021

appId is packaged in your Mini Program. Wechat knows what to do and doesn't need you to put it in the request.
Why not just write it as xxx: because the document doesn't say it can be written that way.


Mini Program has a configuration file project.config.json, that has written some information about Mini Program. Getting code is also described in detail in Wechat's api document

clipboard.png


1.wx.login codeapp.jsonLoad
2.appid   https://mp.weixin.qq.com  =>
3.https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code
codeappidopenid  session_key
4.

everyone upstairs mentioned it, and appid wrote it in the configuration file.
then, the most important thing is not code, but the openid and unionid obtained by combining back-end authentication are really meaningful to the user's identity.

Menu