jssdk.js 1.2 KB

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