Micro-channel sharing Code Package

wxShare.js

( Function () {
     var wxShare = function (the opts) {
         var Defaults = { 
            getWxConfigUrl: '',          // obtain micro-channel interfaces authority URL 
            orDebug: to false ,              // is turned debug mode 
            title: '',                   // share title 
            desc: ''                    // Share description 
            wxUrl: '',                   // participate url signature 
            link: '',                    // share links 
            imgUrl: '',                  //Share icon 
            Success: function () {},       // the user to confirm execution of the callback function to share 
            Cancel: function () {}         // user cancels the execution of the callback function sharing 
        }; 

        var _opts = $ .extend (Defaults, the opts) ; 

        // Get the micro channel privileges 
        $ .ajax ({ 
            URL: _opts [ 'getWxConfigUrl' ], 
            type: 'the POST' , 
            dataType: 'JSON' , 
            Data: {SHARE_URL: _opts [ 'wxUrl' ]}, 
        }) 
        .done ( function (RES) {
             IF( Typeof RES == 'Object' ) {
                 // by config interface injection authority to verify the configuration 
                wx.config ({
                     // turn on debug mode, all calls api return value in the client alert came out, to see incoming parameters, you can open the pc side, will play parameter information through log, will be printed only when the pc. 
                    Debug: _opts [ 'orDebug' ],
                     // required, a unique identification number of public 
                    appId: res.appId,
                     / / mandatory, timestamps generated signature 
                    timestamp: res.timestamp,
                     // required to generate a random string signature 
                    nonceStr: res.nonceStr,
                     // required, signatures, see Appendix 1
                    Signature: res.signature,
                     // Required, JS required interface list 
                    jsApiList: [ 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ' ] 
                }); 
                // process the success or failure of authentication config 
                _wxReady (res.url); 
            } the else { 
                the console.log ( 'micro-channel acquisition failure interfaces permission!' ); 
            } 
        }) 
        .fail ( function () { 
            the console.log ( "right fails to obtain micro-channel interfaces!" ); 
        }); 

        // process the verification is successful config or failure 
        var _wxReady = function(URLs) {
             // wxConfig successful authentication process 
            wx.ready ( function () { 

                // Share circle of friends 
                wx.onMenuShareTimeline ({ 
                    title: _opts [ 'title' ], 
                    Link: _opts [ 'Link' ], 
                    for imgUrl: _opts [ 'for imgUrl' ], 
                    Success: _opts [ 'Success' ], 
                    Cancel: _opts [ 'Cancel' ] 
                }); 

                // Share to friends 
                wx.onMenuShareAppMessage ({ 
                    title: _opts [ 'title' ],
                    desc: _opts [ 'desc' ], 
                    link: _opts [ 'link' ], 
                    for imgUrl: _opts [ 'for imgUrl' ],
                     // type: '', // the type of sharing, music, video, or link, link the default is not filled 
                    // the dataUrl: '', // if the type is music or video, are to provide data links, default is empty 
                    Success: _opts [ 'Success' ], 
                    Cancel: _opts [ 'Cancel' ] 
                }); 

                // share QQ 
                wx.onMenuShareQQ ({ 
                    title: _opts [ 'title' ], 
                    desc: _opts [ 'desc'],
                    Link: _opts [ 'Link' ], 
                    for imgUrl: _opts [ 'for imgUrl' ], 
                    Success: _opts [ 'Success' ], 
                    Cancel: _opts [ 'Cancel' ] 
                }); 
            }); 

            // wxConfig verification function returns a failure 
            wx. error ( function (RES) { 
                the console.log (RES, 'wxConfig authentication failed' ) 
            }); 
        }; 
    }; 

    window.wxShare = wxShare; 

}) ();

transfer:

// determines whether the built-in browser micro-channel 
IF (ua.match (/ MicroMessenger / I) == 'micromessenger' ) {
         // micro channel sharing 
        new new wxShare ({ 
            getWxConfigUrl: "../advice/getWxConfig" , 
            title: 'send you 68 yuan a red envelope, assists your 618 ' , 
            desc: ' God Member voucher day, rob 61.8 yuan no threshold '! , 
            wxUrl: thisUrl, 
            Link: thisUrl, 
            // imgUrl: "../js/sales/activity618/images /20190606154315.png ", 
            for imgUrl:" http://www.800pharm.com/shop/js/sales/activity618/images/20190606154315.png " , 
            Success: function () {
                the console.log ("Sharing Success" ); 
            }, 
            Cancel: function () { 
                the console.log ( "Sharing Failed" ); 
            } 
        }); 
    }

The complete code explanation please move https://github.com/lianglixiong/wechat.js

Guess you like

Origin www.cnblogs.com/LLX8/p/11004862.html