jwx.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import * as config from '../../config'
  2. const jweixin = require('./index')
  3. const configWeiXin = async function(callback) {
  4. uni.request({
  5. url: config.def().baseUrl + '/m.api',
  6. data: {
  7. _gp: 'user',
  8. _mt: 'getH5Sign',
  9. url: window.location.href
  10. },
  11. method: 'POST',
  12. header: {
  13. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  14. },
  15. success: (res) => {
  16. if (res.statusCode === 200) {
  17. if (res.data.errno === 200) {
  18. let resConfig = res.data.data
  19. if (resConfig) {
  20. let apiList = [ // 可能需要用到的能力
  21. 'chooseWXPay'
  22. ];
  23. let info = {
  24. debug: config.def().debug, // 调试,发布的时候改为false
  25. appId: config.def().h5Appid,
  26. nonceStr: resConfig.noncestr,
  27. timestamp: resConfig.timestamp,
  28. signature: resConfig.sign,
  29. jsApiList: apiList
  30. };
  31. jweixin.config(info);
  32. jweixin.error(err => {
  33. console.log('config fail:', err);
  34. });
  35. jweixin.ready(res => {
  36. if (callback) callback(jweixin); // 配置成功
  37. });
  38. }
  39. }
  40. }
  41. }
  42. })
  43. }
  44. export {
  45. configWeiXin
  46. }