jssdk.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // 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. header: {
  14. 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
  15. },
  16. data: {
  17. "url": url
  18. },
  19. method: 'GET',
  20. success: (res) => {
  21. console.log('请求的签名的参数')
  22. console.log(res)
  23. let apiList = [ // 可能需要用到的能力 需要啥就写啥。多写也没有坏处
  24. 'openLocation',
  25. 'getLocation',
  26. 'scanQRCode'
  27. ];
  28. let info = {
  29. debug: false, // 调试,发布的时候改为false
  30. appId: res.data.appid,
  31. nonceStr: res.data.nonceStr,
  32. timestamp: parseInt(res.data.timestamp),
  33. signature: res.data.sha_str,
  34. jsApiList: apiList
  35. };
  36. jweixin.config(info);
  37. jweixin.error(err => {
  38. console.log('config fail:', err);
  39. return
  40. });
  41. jweixin.ready(res => {
  42. // if (callback) callback(jweixin);
  43. });
  44. }
  45. });
  46. // end
  47. }