The following code is saved as get_sdkper.php
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
require _ once“jssdk . PHP”;
// 1. Note: All JS interfaces can only be called under the domain name bound by the official WeChat account. WeChat official account developers need to log on to the WeChat public platform, enter the "Function Settings" of "WeChat official account settings" and fill in the "JS interface security domain name".
//2. Fill in appid and password.
$appid= "your appid ";;
$secret= "your secret";
$ getUrl = $ _ POST[" URL "];
$jssdk = new JSSDK($appid,$secret,$ getUrl);
$ sign package = $ jssdk-& gt; GetSignPackage();
echo("{\"appId\":\ ")。 $signPackage["appId"]。 \ ",\" timestamp \ ":\". $signPackage["timestamp"]。 \ ",\ " non centr \ ":\ "。 $ sign package[" non centr "]。 \ ",\" Signature \ ":\". $signPackage["signature"]。 \ ",\"url\":\ "。 $signPackage["url"]。 \"}");
& gt
The following is the calling method:
//Call the WeChat JS API interface
var GetappId= " ",Gettimestamp= " ",GetnonceStr = " ",Getsignature =
Function call WechatJSAPI ()
{
$.ajax({
Website: "get_sdkper.php",
Type: Post,
data:" URL = "+escape(location . href . split(' # ')[0]),
Data type: "JSON",
Success: Function (Result) {
var resultData = $。 EvalJSON (result);
if(resultData){
GetappId = resultData.appId
gettimestamp = result data . timestamp;
getnon castr = result data . non castr;
get signature = result data . signature;
wx.config({
Debugging: false,
appId: GetappId,
Time stamp: Gettimestamp,
non centr:getnon centr,
Signature: Getsignature,
jsApiList: [
Check JsApi',
' onMenuShareTimeline ',
onMenuShareQQ ',
onMenuShareWeibo ',
Hide menu item',
hideAllNonBaseMenuItem,
Select image',
Preview image',
Upload image',
Download image',
' getNetworkType ',
Open position',
Get location',
hideOptionMenu ',
Close window',
Scan QR code',
Select XPay',
' openProductSpecificView ',
Add card',
Select a card',
Open the card'
]
});
}
},
Error: Function () {
//alert ("Failed to connect to the network, please try again." );
}
});
}