jssdk.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // jwx.js
  2. //#ifdef H5
  3. const jweixin = require('jweixin-module')
  4. //#endif
  5. export function configWeiXin(callback) {
  6. const url = window.location.href.split('#')[0];
  7. uni.request({
  8. url: 'https://s.yxin.tech/sign.php', //仅为示例,并非真实接口地址。
  9. header: {
  10. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
  11. },
  12. data:{"url":url},
  13. method: 'GET',
  14. success: (res) => {
  15. console.log('请求的签名的参数')
  16. console.log(res)
  17. let apiList = [ // 可能需要用到的能力 需要啥就写啥。多写也没有坏处
  18. // 'scanQRCode',
  19. 'openLocation'
  20. ];
  21. let info = {
  22. debug: true, // 调试,发布的时候改为false
  23. appId: res.data.appid,
  24. nonceStr: res.data.nonceStr,
  25. timestamp: parseInt(res.data.timestamp),
  26. signature: res.data.sha_str,
  27. jsApiList: apiList
  28. };
  29. jweixin.config(info);
  30. jweixin.error(err => {
  31. console.log('config fail:', err);
  32. return
  33. });
  34. jweixin.ready(res => {
  35. if (callback) callback(jweixin);
  36. });
  37. //end
  38. }
  39. });
  40. }