jssdk.js 1.2 KB

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