Open the h5 webpage in the upper right corner of WeChat and share it with WeChat friends or Moments

First you need a sharing interface address, and then describe the custom image title as follows:
 <script src= " http://res.wx.qq.com/open/js/jweixin-1.0.0.js " ></script >
<script>
$(function() {
    //微信分享
    $.ajax({
        "url":"https://***.***.com/getJsAPITicket",  //接口地址
        "type":"Get",
        "dataType":"json",
        "data":{"url": window.location.href},
        "success":function(data){
            wxstart(data, "");
        }
    });
});
 
function wxstart(data, url){
    var url = '' ;   // Shared article address 
    var appId = data.appId;
     var timestamp = data.timestamp;
     var nonceStr = data.nonceStr;
     var signature = data.signature;
    wx.config({
        debug: false , // Enable the debug mode, the return values ​​of all the apis called will be alerted on the client side, if you want to view the incoming parameters, you can open it on the pc side, and the parameter information will be printed out through the log, only on the pc side will print. 
        appId: appId, // required, the unique identifier of the official account 
        timestamp: timestamp, // required, the timestamp for generating the signature 
        nonceStr: nonceStr, // required, the random string for generating the signature 
        signature: signature, // required , and the signature, see Appendix 1 
        jsApiList: [ " onMenuShareTimeline " , " onMenuShareAppMessage " , " onMenuShareQQ " ] // Required, a list of JS interfaces to be used, see Appendix 2 for a list of all JS interfaces 
    });
     
    wx.ready(function(){
        var imgurl = 'https://' + window.location.hostname + '/static/customerHtml/img/weixinshare.jpg';
        var title = '';
        var desc = '';
        wx.onMenuShareTimeline({
            title: title, // share title 
            desc: desc, // share description 
            link: url, // share link 
            imgUrl: imgurl, // share icon 
            success: function () { 
                 // callback function executed after user confirms sharing 
            },
            cancel: function () {
                // Callback function executed after user cancels sharing 
            }
        });
         
        wx.onMenuShareAppMessage({
            title: title, // share title 
            desc: desc, // share description 
            link: url, // share link 
            imgUrl: imgurl, // share icon 
            type: '' , // share type, music, video or link, leave blank The default is link 
            dataUrl: '' , // If the type is music or video, a data link should be provided, the default is empty 
            success: function () { 
                 // The callback function executed after the user confirms the sharing 
            },
            cancel: function () {
                // Callback function executed after user cancels sharing 
            }
        });
         
        wx.onMenuShareQQ({
            title: title, // share title 
            desc: desc, // share description 
            link: url, // share link 
            imgUrl: imgurl, // share icon 
            success: function () { 
                // callback function executed after user confirms sharing 
            },
            cancel: function () {
               // Callback function executed after user cancels sharing 
            }
        });
    });
}
</script>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325070839&siteId=291194637