function main() {
    const appid = SYSTEM_CONFIG.find(item => item.name === 'wechat_appid').value;
    const secret = SYSTEM_CONFIG.find(item => item.name === 'wechat_appsecret').value;
    const authCode = payload.get().query["code"];

    // 生成授权链接
    // https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx807d86fb6b3d4fd2&redirect_uri=http%3A%2F%2Fdevelopers.weixin.qq.com&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect

    // 通过回调Code换取AccessToken
    let req = {
        url: `https://api.weixin.qq.com/sns/oauth2/access_token?appid=${appid}&secret=${secret}&code=${authCode}&grant_type=authorization_code`
    }

    let res = request.parse(req).body.toObject()
    //     { 
    //   "access_token":"ACCESS_TOKEN",
    //   "expires_in":7200,
    //   "refresh_token":"REFRESH_TOKEN",
    //   "openid":"OPENID",
    //   "scope":"SCOPE"
    // }

    if (!res.access_token) {
        // {"errcode":40029,"errmsg":"invalid code"}
        return errMsg(511, `Token验证不通过,错误代码: ${res.errcode},错误信息: ${res.errmsg}`)
    }


    // 通过AccessToken换取用户信息
    req = {
        url: `https://api.weixin.qq.com/sns/userinfo?access_token=${res.access_token}&openid=${res.openid}&lang=zh_CN`
    }

    res = request.parse(req).body.toObject()
    //     {   
    //   "openid": "OPENID",
    //   "nickname": NICKNAME,
    //   "sex": 1,
    //   "province":"PROVINCE",
    //   "city":"CITY",
    //   "country":"COUNTRY",
    //   "headimgurl":"https://thirdwx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/46",
    //   "privilege":[ "PRIVILEGE1" "PRIVILEGE2"     ],
    //   "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"
    // }

    if (!res.openid) {
        return errMsg(511, `Token验证不通过,错误代码: ${res.errcode},错误信息: ${res.errmsg}`)
    }

    'use api/user/oauth/getUser.js'

    // unionid 在未接入开发者平台的时候是没有的,自行判断是否在sql里面加入union_id的字段

    // 绑定用户
    SQL.push('system_sql', "INSERT INTO sys_users_oauth (relate_id, user_id, login_from, open_id, username, avatar_img, raw_info) VALUES (?,?,?,?,?,?)",
        ex.suid().base58(), tokenInfo.uid, 1, res.openid, res.nickname, res.headimgurl, JSON.stringify(res))
    return okMsg("绑定成功")
}