jssdk.js 1.2 KB

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