yj
2024-12-05 ac3234c308e86f20cc63465573f321561ee00690
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
42
43
44
45
46
47
48
49
50
51
import config from '../../config'
 
const jweixin = require('./index')
 
const configWeiXin = async function(callback) {
    uni.request({
        url: config.baseUrl + '/m.api',
        data: {
            _gp: 'user',
            _mt: 'getH5Sign',
            url: window.location.href
        },
        method: 'POST',
        header: {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        },
        success: (res) => {
            if (res.statusCode === 200) {
                if (res.data.errno === 200) {
                    let resConfig = res.data.data
                    if (resConfig) {
                        let apiList = [ // 可能需要用到的能力
                            'chooseWXPay'
                        ];
                        let info = {
                            debug: config.debug, // 调试,发布的时候改为false
                            appId: config.h5Appid,
                            nonceStr: resConfig.noncestr,
                            timestamp: resConfig.timestamp,
                            signature: resConfig.sign,
                            jsApiList: apiList
                        };
                        jweixin.config(info);
                        jweixin.error(err => {
                            console.log('config fail:', err);
                        });
                    
                        jweixin.ready(res => {
                            if (callback) callback(jweixin); // 配置成功
                        });
                    }
                }
            }
        }
    })
 
}
 
export {
    configWeiXin
}