Welcome
We've been working hard

How to display pictures and texts with WeChat page forwarding and sharing to WeChat friends circle

Prerequisites for H5 pure static page sharing to WeChat friends circle with picture display

1. WeChat official account has been successfully authenticated

2. Add js security domain name to WeChat public account

3. Add IP whitelist (server external network IP)

HTML code part:

 <? php //Step 1. Set appid and appsecret $appid = 'wxbb446b55816eb32b'; // Fill in the appid of the bound WeChat public account here $appsecret = '9288201823b0beda333a9698f861d0a8'; // Fill in the key ID of the bound WeChat public account here //Step 2. Generate a random string of signatures function nonceStr($length){ $str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJK1NGJBQRSTUVWXYZ';// Random string, 62 characters $strlen = 62; while($length > $strlen){ $str .= $ str; $strlen += 62; } $str = str_shuffle($str); return substr($str,0,$length); } //Step 3. Get access_token $result = http_get(' https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= '.$ appid.'&secret='.$appsecret); $json = json_decode($result,true); $access_token = $json['access_token']; function http_get($url){ $oCurl = curl_init(); if(stripos($url,"https://")!== FALSE){ curl_setopt($oCurl,  CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($oCurl,  CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($oCurl,  CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1 } curl_setopt($oCurl, CURLOPT_URL, $url); curl_setopt($oCurl,  CURLOPT_RETURNTRANSFER, 1 ); $sContent = curl_exec($oCurl); $aStatus = curl_getinfo($oCurl); curl_close($oCurl); if(intval($aStatus["http_code"])==200){ return $sContent; }else{ return false; } } //Step 4. Get ticket $url = " https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token= $access_token"; $res = json_decode ( http_get ( $url ) ); $ticket = $res->ticket; //Step 5. Generate the parameters required by wx.config $surl = 'http://'.$_ SERVER['HTTP_HOST'].$_ SERVER['REQUEST_URI']; $ws = getWxConfig( $ticket,$surl,time(),nonceStr(16) ); function getWxConfig($jsapiTicket,$url,$timestamp,$nonceStr) { $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url"; $signature = sha1 ( $string ); $WxConfig["appId"] = $appid; $WxConfig["nonceStr"] = $nonceStr; $WxConfig["timestamp"] = $timestamp; $WxConfig["url"] = $url; $WxConfig["signature"] = $signature; $WxConfig["rawString"] = $string; return $WxConfig; } ?> <! DOCTYPE html> <html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>WeChat page forwarding and sharing to WeChat friends circle with image and text display</title> <meta name='viewport' content='width=device-width,  initial-scale=1.0, maximum-scale=1.0'/> <meta name="keywords" content="WeChat page forwarding and sharing to WeChat friends circle with text display"> <meta name="description" content="WeChat page forwarding and sharing to WeChat friends circle with text and image display"> </head> <body> <div class="swiper-container"> </div> <script src=" http://res.wx.qq.com/open/js/jweixin-1.0.0.js "></script> <script> wx.config({ Debug: true,//Enable the debug mode, and the return values of all the called apis will be displayed in the client alert. To view the passed in parameters, you can open them on the PC side, and the parameter information will be displayed through the log. Only on the PC side will the parameter information be printed. AppId: 'wxbb446b55816eb32b',//Required, the unique identifier of the public account timestamp: "<? php echo $ws["timestamp"]; ?> ",//Required, generate signature timestamp nonceStr: '<?php echo $ws["nonceStr"]; ?>', //  Required. Generate a random string of signatures signature: '<?php echo $ws["signature"]; ?>',//  Mandatory, signature, see Appendix 1 jsApiList: [ 'checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo' ]//Required. See Appendix 2 for the list of JS interfaces to be used }); Var wstitle="Sample preview of WeChat sharing interface";//Fill in the sharing title here Var wsdesc="This is an example preview page of WeChat sharing interface, which can be sent to WeChat to preview and forward to friends or share the circle of friends to see how it works! ";//Fill in the sharing profile here var wslink = "<? php echo $surl; ?>"; // Get a link to share here var wsimg = " http://share.xiaomenshenvip.com/images/shares.jpg ";//Get shared thumbnails here </script> <script src="js/wxshare.js"></script> </body> </html>

wxshare.js:

 wx.ready(function () { //Share with friends wx.onMenuShareTimeline({ title: wstitle, link: wslink, imgUrl: wsimg, success: function () { Alert ('shared successfully '); }, cancel: function () { } }); //Share with friends wx.onMenuShareAppMessage({ title: wstitle, desc: wsdesc, link: wslink, imgUrl: wsimg, success: function () { Alert ('shared successfully '); }, cancel: function () { } }); //Share to QQ wx.onMenuShareQQ({ title: wstitle, desc: wsdesc, link: wslink, imgUrl: wsimg, success: function () { Alert ('shared successfully '); }, cancel: function () { } }); //WeChat to Tencent Weibo wx.onMenuShareWeibo({ title: wstitle, desc: wsdesc, link: wslink, imgUrl: wsimg, success: function () { Alert ('shared successfully '); }, cancel: function () { } }); //Share to QQ space wx.onMenuShareQZone({ title: wstitle, desc: wsdesc, link: wslink, imgUrl: wsimg, success: function () { Alert ('shared successfully '); }, cancel: function () { } }); });

 

Like( zero ) Reward
Do not reprint without permission: New Start Blog » How to display pictures and texts with WeChat page forwarding and sharing to WeChat friends circle


Follow the public account "New Start Software Steward"

Get the latest network resources and cracking software!
Play with all kinds of software

comment Grab the sofa

You must log in before commenting!

 

Reward the author of the article if you think it is useful

Thank you very much for your reward, we will continue to give more high-quality content, let's create a better online world together!

Scan Alipay and reward

Scan WeChat and reward