Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Wechat Custom sharing by php

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to achieve Wechat custom sharing with php. The editor thinks it is very practical, so I hope you can get something after reading this article.

The previous paragraph between Wechat custom sharing, accumulated some experience to share with you.

Steps 1 and 2 are already detailed in the Wechat developer documentation, so let's start with step 3.

Step 3: parameters for Wechat. Except for appId, all parameters are dynamic. Here, I use the php language to generate the parameters at the backend. The code is as follows:

Php side code:

Public function getwxinfo () {$dataurl = I ('dataurl'); include ('. / ThinkPHP/Library/Vendor/jssdk/jssdk.php'); $jssdk = new\ JSSDK ('appId','appSecret'); $signPackage = $jssdk- > GetSignPackage ($dataurl); exit (response

When you generate a signature, you must get the URL of the current page, so $dataurl is dynamically obtained through the following JS, so keep in mind.

JS side code:

Var dataurl = _ window.location.href; $.ajax ({type:'post', data: {'dataurl':dataurl}, url:'/index.php/Home/Index/getwxinfo', dataType:'json', success:function (json) {var list = json.data; var appId = list.appId; var timestamp = list.timest var nonceStr = list.nonceStr; var signature = list.signature; weixinInfo (appId,timestamp,nonceStr,signature) }, error:function () {/ / alert ('the network is not powerful...)}) Function weixinInfo (appId,timestamp,nonceStr,signature) {wx.config ({debug: false, appId: appId,timestamp: timestamp,nonceStr: nonceStr,signature: signature, jsApiList: ['checkJsApi', / / determine whether the current client version supports specifying JS interface' onMenuShareTimeline', / / share to moments' onMenuShareAppMessage', / / share to friends' onMenuShareQQ' / / share to QQ 'onMenuShareWeibo' / / share to Weibo]}) } wx.ready (function () {/ / Wechat friend var s_title = 'sharing title'; var s_desc = 'sharing description'; var s_link = 'shared link'; var s_imgUrl = 'photo link' Wx.onMenuShareAppMessage (for example, API title: s_title sharing to moments, / / sharing title desc: s_desc, / / sharing description link: s_link, / / sharing link imgUrl: s_imgUrl, / / sharing icon success: function () {}, cancel: function () {}}) / / moments wx.onMenuShareTimeline ({title: s_title, / / sharing title link: s_link, / / sharing link imgUrl: s_imgUrl, / / sharing icon success: function () {}, cancel: function () {}}) / / QQ friend wx.onMenuShareQQ ({title: s_title, / / sharing title desc: s_desc, / / sharing description link: s_link, / / sharing link imgUrl: s_imgUrl, / / sharing icon success: function () {}, cancel: function () {}});}); wx.error (function (res) {alert (res.errMsg); / / print error message. And set debug:false, set to debug:ture, you can see the pop-up error message}); on "php how to achieve Wechat custom sharing" this article is shared here, I hope the above can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report