1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import wx from "weixin-js-sdk";
- import axios from 'axios';
- export function getWxCode(title, image, url, desc) {
- let params = {
- link: location.href,
- url: location.href
- }
- let postApi = '/test/face/wxapi/wx/signature'
- if (process.env.NODE_ENV !== 'development') {
- postApi = 'https://operationapi.mige.tv/wxapi/wx/signature'
- }
- axios.post(postApi, params)
- .then(res => {
- console.log(res.data.data)
- wx.config({
- debug: false, // 开启调试模式
- appId: res.data.data.appId, // 必填,公众号的唯一标识
- timestamp: res.data.data.timestamp, // 必填,生成签名的时间戳
- nonceStr: res.data.data.nonceStr, // 必填,生成签名的随机串
- signature: res.data.data.signature, // 必填,签名
- jsApiList: [
- "updateTimelineShareData",
- "updateAppMessageShareData",
- "onMenuShareAppMessage",
- "onMenuShareTimeline"
- ] // 必填,需要使用的JS接口列表
- });
- wx.ready(function () { //需在用户可能点击分享按钮前就先调用
- wx.updateAppMessageShareData({
- title: title, // 分享标题
- desc: desc, // 分享描述
- link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
- imgUrl: image, // 分享图标
- success: function () {
- console.log("成功")
- },
- fail: function () {
- console.log('取消')
- }
- })
- wx.onMenuShareTimeline({
- title: title, // 分享标题
- desc: desc, // 分享描述
- link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
- imgUrl: image, // 分享图标
- success: function () {
- console.log("成功")
- },
- fail: function () {
- console.log('取消')
- }
- });
- });
- })
- .catch(err => {
- console.error(err);
- })
- }
|