Marlboro-pm

使用微信进行分享的接口

可用在多个项目中  套路一样 只需要改掉基础数据

import ajax from \'ajax\'
import { getQueryStr } from "../utils.js"
import { URL } from \'../config.js\'
let server = getQueryStr("server") || "hjwp";
let debug = getQueryStr("debug") || false;
class WeiXin {
constructor() {
let title = "分享的题目";
let desc = `可有可无`;
let link = `${URL.gzh}Redirect?url=fanpai&server=${server}&{shareId}`;
let imgUrl = `${URL.static}questionnaire/static/images/share.png`;
this.timeLine = { title, imgUrl }
this.app = { title, desc, imgUrl }
let param = {}
this.getJsConfig((data, err) => {
if (err) {
return false
};
wx.config(data);
wx.ready(() => {
wx.onMenuShareTimeline(this.timeLine)
wx.onMenuShareAppMessage(this.app)
wx.hideMenuItems({
menuList: [\'menuItem:refresh\', \'menuItem:copyUrl\', \'menuItem:originPage\', \'menuItem:openWithQQBrowser\', \'menuItem:openWithSafari\', \'menuItem:share:qq\', \'menuItem:share:QZone\']
})
wx.showMenuItems({
menuList: [\'menuItem:share:timeline\', \'menuItem:share:appMessage\']
})
this.handleFontSize();
})
})
}
getJsConfig(callback) {
let url = `${URL.gzh}wechatapi/GetJsconfig?debug=${debug}`;
ajax.get(url, \'GET\', function(data, err) {
callback(data, err)
})
}
setShareTimeLine(timeLine) {
let { title, link, imgUrl, callback } = timeLine
this.timeLine.title = title ? title : this.timeLine.title
this.timeLine.link = title ? title : this.timeLine.link
this.timeLine.imgUrl = title ? title : this.timeLine.imgUrl
if (typeof callback == "function") {
this.timeLine.success = callback
}
}
setShareApp(app) {
let { title, link, imgUrl, callback } = app
this.app.title = title ? title : this.app.title
this.app.desc = title ? title : this.app.desc
this.app.link = title ? title : this.app.link
this.app.imgUrl = title ? title : this.app.imgUrl
if (typeof callback == "function") {
this.app.success = callback
}

}
setShareId(shareId) {
this.timeLine.link = this.timeLine.link.replace(\'{shareId}\', "shareId=" + shareId)
this.app.link = this.app.link.replace(\'{shareId}\', "shareId=" + shareId) } handleFontSize() {   // 设置网页字体为默认大小
if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
WeixinJSBridge.invoke(\'setFontSizeCallback\', { \'fontSize\': 0 });   // 重写设置网页字体大小的事件
WeixinJSBridge.on(\'menu:setfont\', function() { WeixinJSBridge.invoke(\'setFontSizeCallback\', { \'fontSize\': 0 }); }); } }}export default new WeiXin()

分类:

技术点:

相关文章:

  • 2021-09-27
  • 2021-11-14
  • 2021-11-01
  • 2021-12-31
  • 2021-11-17
  • 2021-11-03
  • 2021-09-27
猜你喜欢
  • 2021-11-01
  • 2021-08-13
  • 2021-09-24
  • 2021-11-01
  • 2021-12-29
相关资源
相似解决方案