zoukankan      html  css  js  c++  java
  • 使用微信进行分享的接口

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

    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()
  • 相关阅读:
    利用Jquery实现http长连接(LongPoll)
    使用C#把发表的时间改为几年前,几个月,几天前,几小时前,几分钟前,或几秒前
    跨域调用接口——WebClient通过get和post请求api
    Url重写——伪静态实现
    控制反转(IOC)
    文件上传之——用SWF插件实现文件异步上传和头像截取
    利用枚举展示下拉列表
    时间格式转换—将后台返回的/Date(1448954018000)/格式转换为正常的时间格式
    @RenderSection,@RenderPage,@RenderBody介绍
    简单工厂模式(转)
  • 原文地址:https://www.cnblogs.com/Marlboro-pm/p/6472603.html
Copyright © 2011-2022 走看看