Main function, get the user to share the status, share the success, share the failure and so on
Code fragment:
$noncestr = Getrandstr (15);
$timestamp = time ();
$access _token = Access_token ($db);
Var_dump ($access _token);
Exit ();
$url = ' https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token= '. $access _token. ' &type=jsapi ';
$ret _json = curl_get_contents ($url);
$ret = Json_decode ($ret _json);
$_session[' jsapi_ticket ' = $ret-> ticket;
Var_dump ($ret);
$strvalue = ' jsapi_ticket= '. $_session[' Jsapi_ticket ']. ' &noncestr= '. $noncestr. ' ×tamp= '. $timestamp. ' &url=http://'. $_server[' http_host '].$_server[' Request_uri '];
$signature = SHA1 ($strvalue);
Var_dump ($strvalue);
$smarty->assign (' timestamp ', $timestamp);
$smarty->assign (' Noncestr ', $noncestr);
$smarty->assign (' signature ', $signature);
The PHP section is mainly through the AppID and secret to obtain token after the token to obtain a ticket.
Output time, output random string, output encrypted signature
JS section:
Wx.config ({
Debug:false,//Turn on debug mode, call the return value of all APIs will be in the client alert, to see the incoming parameters, can be opened on the PC side, the parameter information will be typed through the log, only on the PC side will print.
AppId: ' xxxxx ',//required, unique identification of public number
Timestamp: ' {$timestamp} ',//required, generate signature timestamp
Noncestr: ' {$nonceStr} ',//required, generate signed random string
Signature: ' {$signature} ',/must be filled, signed, see Appendix 1
Jsapilist: [' onmenusharetimeline ', ' onmenushareappmessage ']//required, need to use the JS interface list, all JS interface list See Appendix 2
});
Wx.ready (function () {
Wx.onmenusharetimeline ({
Title: ' Share title ',//share titles
Link: ' http://baidu.com ',//share links
Imgurl: '/wp-content/themes/weisaysimple/images/random/tb5.jpg ',//share icon
Success:function () {
callback function executed after user confirms share
alert (1111);
},
Cancel:function () {
callback function executed after user cancels sharing
Alert (222);
}
});
Config information is validated after the Ready method is executed, all interface calls must be the result of the Config interface, config is a client's asynchronous operation, so if you need to call the relevant interface when the page is loaded, The relevant interfaces must be called in the ready function to ensure proper execution. For interfaces that are invoked when a user fires, they can be called directly and do not need to be placed in the ready function.
});