jssdk.js 1.2 KB

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