Developing JSSDK of wechat web page in PHP or HTML

Keywords: PHP iOS

Recently, the company has developed several wechat pages for publicity, which mainly use JSSDK, and how to use it to share small icons and text descriptions with friends and friends.

First, we need a certified service number to add our own server path under the public address Settings > function settings ->JS interface security domain name.

Then add the text file of wechat under the path

Finally, the JS file is introduced into the page

The following can be used in the page. First, introduce jssdk.php in the page header:

<?php
require_once "php/jssdk.php";
$jssdk = new JSSDK("WeChat APPID", "WeChat cipher");
$signPackage = $jssdk->GetSignPackage();
?>

The file of jssdk.php can be obtained from the wechat demo file.

If it's HTML, use JS to call it.

       var content = "Annual celebration of cloud produced tobacco brand";

        wx.config({
            // Configuration information, even if not correct, can use wx.ready
            debug: false,
            appId: '<?php echo $signPackage["appId"];?>',
            timestamp: '<?php echo $signPackage["timestamp"];?>',
            nonceStr: '<?php echo $signPackage["nonceStr"];?>',
            signature: '<?php echo $signPackage["signature"];?>',
            jsApiList: ['checkJsApi','onMenuShareTimeline','onMenuShareAppMessage']
        });


    function autoPlayAudio1() {
        wx.ready(function(res) {

             //Share with friends
        wx.onMenuShareAppMessage({
            title: 'The Tianshan Mountains are beautiful and fragrant',       // Share title
            desc: content, // Sharing description
            link: 'http://www. domain name.com/JS/index1.php'/ / / share link, the link domain name or path must be consistent with the current page corresponding to the public number JS security domain name.
            imgUrl: 'https://www. domain name. com/JS/logo1.png ', / / share Icon
            type: '',                               // Sharing type, music, video or link, no default is link
            dataUrl: '',                            // If the type is music or video, you need to provide data link, which is empty by default
            trigger: function(res) {},
            success: function(res) {},
            cancel: function(res) {},
            fail: function(res) {}
        }); 

       //Share with friends
       wx.onMenuShareTimeline({
            title: 'The Tianshan Mountains are beautiful and fragrant', // Share title
            link: 'http://www. domain name.com/JS/index1.php'/ / / share link, the link domain name or path must be consistent with the current page corresponding to the public number JS security domain name.
            imgUrl: 'https://www. domain name. com/JS/logo1.png ', / / share Icon
            trigger: function(res) {},
            success: function(res) {},
            cancel: function(res) {},
            fail: function(res) {}
        });  
            
       
        });

        wx.checkJsApi({
            jsApiList: ['onMenuShareAppMessage','onMenuShareTimeline'], // List of JS interfaces to be detected
            success: function(res) {
                    // alert(res);
            }
        });

        wx.error(function(res){

         });
    
        }

Here are the points to note:

1, imgUrl must start with https, otherwise IOS system does not support small icons.

2, MP > verify > iq2j5o8aszoyj2g4.txt, the file must be placed in the http://www.domain.com/JS/ The following description will take effect.

Posted by jane on Tue, 31 Dec 2019 08:05:40 -0800