In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how to use the official account js-sdk of Wechat in php". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how to use the official account js-sdk of Wechat in php".
To test the interface function of js, I used a BAE server, not a SAE server. The SAE server cannot write to the file and there will be a problem with the test.
What is js-sdk? let me first demonstrate the specific role of the js-sdk interface.
I randomly open a piece of push article on Wechat as shown below:
Click on the first article
The above is our link article. If we send this article to our friends, the display effect is as follows:
Let's share it to WeChat moments and see the effect:
Why is the same article link, in the official account, send to friends, send to moments to show the interface effect is not the same. The display effect of the official account is because the Wechat public account calls the Wechat message interface when pushing, and the latter two are because the page calls the sdk API related to js-sdk.
Send it to a friend and call the js API to get the click status of the "share to friend" button and customize the sharing content interface.
Send it to moments and call the API js to get the status of the "share to moments" button and customize the API for sharing content.
Let's implement the steps to call the js-sdk interface:
Step 1: enter the "function Settings" of "official account Settings" and fill in "JS API Security Domain name" on Wechat public platform.
As shown below:
Only pages placed under this domain name can call the js API.
Step 2: http://demo.open.weixin.qq.com/jssdk/sample.zip connect to this address to download, open the php folder inside, you will find 4 php files
The first three php files are configuration files. Don't touch them. Sample.php is the connection page we opened in Wechat, where we write our page code. This file is used for testing, and the code in it is different from the original version.
I rely on Zhu Bajie Hello Tang Sheng / / this is a js-sdk file, it must be introduced. Var button = document.getElementsByTagName ("button"); var btn = document.getElementById ("btn"); var div = document.getElementsByTagName ("div") [0]; var btn1 = document.getElementById ("btn1"); / / wx represents an object built by js-sdk. Config () is one of its methods, and this interface is used to verify the configuration. Wx.config ({debug: true,//true means that each call to an interface information will alert a string on the page. It is convenient to test whether China can call the interface correctly. AppId:', timestamp:, nonceStr:', signature:', / / the above four parameters, if you want to learn more about their sources, check out the jssdk.php code. The testing process does not require any action on the above code. JsApiList: [/ / all API to be called should be added to this list. 'onMenuShareAppMessage',// to get the click status of the "share with friends" button and customize the sharing content interface. The API for chooseImage',// to obtain mobile photos and the API for openLocation'// to obtain Wechat map]}); / / all js calling APIs should be placed in the ready () below. Wx.ready (function () {/ / call API / / here to get the click status of the "share with your friend" button, click it and send it to your friend on Wechat The push display on Wechat is the following data wx.onMenuShareAppMessage ({title: 'great saint', / / sharing title desc:'I will stick to it', / / sharing description link: 'http://www.baidu.com', / / sharing link imgUrl:' http://discuz.comli.com/weixin/weather/icon/cartoon.jpg', / / sharing icon type: 'link' / / sharing type: music, video or link If left empty, it defaults to link dataUrl:'', / / if type is music or video, provide a data link. Default is empty success: function () {/ / callback function alert ("success") executed after the user confirms sharing. }, cancel: function () {/ / callback function alert ("error") executed after the user cancels sharing;}}); / / take photos or select from mobile photo albums. Click the button on the page to call the photo album on your phone. Btn.onclick = function () {wx.chooseImage ({count: 1, / / default 9 sizeType: ['original',' compressed'], / / you can specify whether it is the original image or a compressed image. By default, both have sourceType: ['album',' camera'], / / you can specify whether the source is a photo album or a camera, and success: function (res) {var localIds = res.localIds by default / / returns the local ID list of the selected photos. LocalId can display the image as the src attribute of the img tag.)}; / Wechat has a built-in map API. Click this button to go to the map page showing the current location btn1.onclick = function () {wx.openLocation ({latitude: 0, / / latitude, floating-point number, ranging from 90 to-90 longitude: 0, / / longitude, floating-point number, range from 180 to-180. Name:'', / / location name address:'', / / address details description scale: 1, / / map zoom level, shaping value, range from 1 to 28. Default is maximum infoUrl:''/ / the hyperlink displayed at the bottom of the View location interface can be clicked to jump});}}) / / wx.checkJsApi ({/ / jsApiList: ['onMenuShareAppMessage'], / / list of JS interfaces to be tested. For a list of all JS interfaces, please see Appendix 2: success: function (res) {/ returned in the form of key-value pairs. Available API values true are not available as false// e.g. {"checkResult": {"chooseImage": true}, "errMsg": "checkJsApi:ok"} / / alert ("success"). / /} / /}); / / btn.onclick = function () {/ / div.innerText = "the Great Sage of Heaven" / / wx.onMenuShareAppMessage ({/ / title: 'great saint', / / sharing title / / desc:'I insist', / / sharing description / / link: 'http://www.baidu.com', / / sharing link / / imgUrl:' http://discuz.comli.com/weixin/weather/icon/cartoon.jpg', / / sharing icon / type: 'link', / / sharing type Music, video or link If left empty, defaults to link// dataUrl:'', / / if type is music or video, provide a data link. Default is empty / / success: function () {/ callback function / / alert ("success") executed after the user confirms sharing. / /}, / / cancel: function () {/ callback function executed after the user cancels sharing / / alert ("error"); / /} / /}); / /}
To test the interface function of js, I used a BAE server, not a SAE server. The SAE server cannot write to the file and there will be a problem with the test.
The above is all the contents of this article entitled "how to use Wechat official account js-sdk in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.