How to share micro-trust in JavaScript

Source: Internet
Author: User
Tags ticket


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. ' &timestamp= '. $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.
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.