Current location - Quotes Website - Signature design - After WeChat opens the JS-SDK, what can developers do? What is the meaning of openness
After WeChat opens the JS-SDK, what can developers do? What is the meaning of openness

Log in to your WeChat platform and click "Official Account Settings". 2 Click "Function Settings" and then click "Settings". 3Set the JS interface security domain name. The first-level domain name filled in here is without /cgi-bin/token?grant_type=client_credential&appid='.'Your AppID'.'&secret='.'Your AppSecret');$res=json_decode($res,true );$token=$res['access_token'];//Note: The obtained token needs to be cached (or written to the database)///cgi-bin/token cannot be accessed frequently, there are times per day Limitations //The validity period of the token returned through this interface is currently 2 hours. After the token expires, the JS-SDK cannot be used. //Therefore, the token value is cached here for 1 hour, which is less than 2 hours. After the cache expires, obtain a new token from the interface, so // that the token expiration can be avoided. //S() is the cache function of ThinkPhp. If you are not using the ThinkPhp framework, you can use your cache function or use the database to save it. S('access_token',$token,3600);}return$token;}Note: The length of the returned access_token must be at least 512 bytes. Interface return value: {"access_token":"ACCESS_TOKEN","expires_in":7200}{"access_token":"vdlThyTfyB0N5eMoi3n_aMFMKPuwkE0MgyGf_0h0fpzL8p_hsdUX8VGxz5oSXuq5dM69lxP9wBwN9Yzg-0kVH Y33BykRC0YXZZZ-WdxEic4","expires_in":7200}6 Get the jsapi ticket. jsapi_ticket is a temporary ticket used by public accounts to call the WeChat JS interface. Under normal circumstances, the validity period of jsapi_ticket is 7200 seconds and is obtained through access_token. functionwx_get_jsapi_ticket(){$ticket="";do{$ticket=S('wx_ticket');if(!empty($ticket)){break;}$token=S('access_token');if(empty($ token)){wx_get_token();}$token=S('access_token');if(empty($token)){logErr("getaccesstokenerror.");break;}$url2=sprintf("/cgi-bin/ ticket/getticket?access_token=%s&type=jsapi",$token);$res=file_get_contents($url2);$res=json_decode($res,true);$ticket=$res['ticket'];//Note : Here you need to cache the obtained ticket (or write it to the database) //Ticket, like token, cannot be obtained by frequently accessing the interface. After each acquisition, we save it. S('wx_ticket',$ticket,3600);}while(0);return$ticket;}Interface return value: {"errcode":0,"errmsg":"ok","ticket":"sM4AOVdWfPE4DxkXGEs8VMKv7FMCPm-I98 -klC6SO3Q3AwzxqljYWtzTCxIH9hDOXZCo9cgfHI6kwbe_YWtOQg","expires_in":7200}7 signature, connect jsapi_ticket, noncestr, timestamp, and shared URLs in alphabetical order to perform sha1 signature. noncestr is any string you set. timestamp is the timestamp.

$timestamp=time();$wxnonceStr="Any string";$wxticket=wx_get_jsapi_ticket();$wxOri=sprintf("jsapi_ticket=%s&noncestr=%s×tamp=%s&url=%s",$wxticket,$ wxnonceStr,$timestamp,'URL to be shared (starting from http, including parameters if there are parameters)');$wxSha1=sha1($wxOri);END Step 2 After adding JS code to generate a signature, you can use the js code . In your html, just make the following settings.