zhaoxiaoqiang
2022-08-17 dfb102e3d9f1bf1196be041cd1f4a3f50727bdda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * @Author: 小明丶
 * @Date: 2020-05-07 18:35:25
 * @LastEditors: 小明丶
 * @LastEditTime: 2020-10-27 20:10:04
 * @Description: 
 */
 
/**
 * 微信授权
 * @param appid 公众号的唯一标识
 * @param redirect_uri 授权后重定向的回调链接地址(登录后授权了最好返回到登录跳转的主页面), 请使用 urlEncode 对链接进行处理,用户同意授权,页面将跳转至 redirect_uri/?code=CODE&state=STATE。
 * @param scope 应用授权作用域,snsapi_base (不弹出授权页面,直接跳转,只能获取用户openid),snsapi_userinfo (弹出授权页面,可通过openid拿到昵称、性别、所在地。并且, 即使在未关注的情况下,只要用户授权,也能获取其信息 )
 * @param state 重定向后会带上state参数,开发者可以填写a-zA-Z0-9的参数值,最多128字节
 */
 
//  export function goWeChat(appid,redirect_uri){
//         // 拼接微信授权页面链接
//         var url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect`
        
//         // 判断用户是否已经授权
//         if(window.localStorage.axx_ins_client_openId == 'undefined' || !localStorage.axx_ins_client_openId){
//             window.location.href = url
//             // 在回调页面去获取到授权返回的code,并且传递给后端
//         }
//     }
    export class  GoWeChat {
        constructor(appid,redirect_uri){
            this.appid = appid
            this.redirect_uri = redirect_uri
        }
        gocontract(){
            // 拼接微信授权页面链接
            var url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.appid}&redirect_uri=${this.redirect_uri}&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect`
             // 判断用户是否已经授权
            if(window.localStorage.axx_ins_client_openId == 'undefined' || !localStorage.axx_ins_client_openId){
                window.location.href = url
                // 在回调页面去获取到授权返回的code,并且传递给后端
            }
        }
    }