cmWXjssdk.js 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. var wxJssdkMixin = function () {
  2. return {
  3. data() {
  4. return {
  5. appId: 'wx91c4152b60ca91a3', // 微信公众号appId
  6. jsApiList: ['updateAppMessageShareData', 'onMenuShareAppMessage', 'updateTimelineShareData', 'onMenuShareTimeline'], // 微信配置可用权限
  7. }
  8. },
  9. methods: {
  10. setWxConfig(callback) {
  11. const url = 'https://www.caimei365.com/serviceSettlement.html?id=0'
  12. SettlementService.getWxConfig({
  13. appId: this.appId,
  14. url
  15. }, (res) => {
  16. const data = res.data
  17. const wx = window.wx
  18. console.log(data)
  19. if (this.isWeChat()) {
  20. wx.config({
  21. debug: true, // dev === 'development' 开启调试模式,调用的所有 api 的返回值会在客户端 alert 出来,若要查看传入的参数,可以在 pc 端打开,参数信息会通过 log 打出,仅在 pc 端时才会打印。
  22. appId: this.appId, // 必填,公众号的唯一标识
  23. timestamp: data.timestamp, // 必填,生成签名的时间戳
  24. nonceStr: data.noncestr, // 必填,生成签名的随机串
  25. signature: data.signature, // 必填,签名
  26. jsApiList: this.jsApiList // 必填,需要使用的 JS 接口列表
  27. })
  28. callback && callback(wx)
  29. wx.error(function (err) {
  30. console.warn(err)
  31. })
  32. }
  33. })
  34. },
  35. isWeChat() {
  36. return /MicroMessenger/i.test(navigator.userAgent);
  37. },
  38. setWxReady(wx) {
  39. console.log('wx', wx)
  40. wx.ready(function () {
  41. // wx.onMenuShareAppMessage({
  42. // title: '采美商城', // 分享标题
  43. // desc: '采美商城', // 分享描述
  44. // link: 'https://www.caimei365.com/serviceSettlement.html?id=0', // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
  45. // imgUrl: 'https://static.caimei365.com/app/img/serviceProvider/H5/search-content-bg.png',
  46. // success: () => {
  47. // },
  48. // fail: () => {
  49. // window.location.reload();
  50. // }
  51. // })
  52. // wx.onMenuShareTimeline({
  53. // title: '采美商城', // 分享标题
  54. // desc: '采美商城', // 分享描述
  55. // link: 'https://www.caimei365.com/serviceSettlement.html?id=0', // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
  56. // imgUrl: 'https://static.caimei365.com/app/img/serviceProvider/H5/search-content-bg.png',
  57. // success: () => {
  58. // },
  59. // fail: () => {
  60. // }
  61. // })
  62. wx.updateAppMessageShareData({
  63. title: '采美商城', // 分享标题
  64. desc: '采美商城', // 分享描述
  65. link: 'https://www.caimei365.com/serviceSettlement.html?id=0', // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
  66. imgUrl: 'https://static.caimei365.com/app/img/serviceProvider/H5/search-content-bg.png',
  67. success: () => {
  68. },
  69. fail: () => {
  70. }
  71. })
  72. wx.updateTimelineShareData({
  73. title: '采美商城', // 分享标题
  74. desc: '采美商城', // 分享描述
  75. link: 'https://www.caimei365.com/serviceSettlement.html?id=0', // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
  76. imgUrl: 'https://static.caimei365.com/app/img/serviceProvider/H5/search-content-bg.png',
  77. success: () => {
  78. },
  79. fail: () => {
  80. }
  81. })
  82. })
  83. }
  84. }
  85. }
  86. }()