Created
January 14, 2015 07:17
-
-
Save c9n/a26924bba541e926c477 to your computer and use it in GitHub Desktop.
获取微信 jsapi_ticket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Class WeixinApi { | |
private $appid; | |
private $secret; | |
function __construct ($appid, $secret) { | |
$this->appid = $appid; | |
$this->secret = $secret; | |
} | |
public function get_access_token () { | |
$api = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $this->appid . '&secret=' . $this->secret; | |
$resp = json_decode(file_get_contents($api), true); | |
return is_null($resp) ? null : $resp['access_token']; | |
} | |
public function get_jsapi_ticket () { | |
$access_token = $this->get_access_token(); | |
$api = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=' . $access_token; | |
$resp = json_decode(file_get_contents($api), true); | |
return is_null($resp) ? null : $resp['ticket']; | |
} | |
} | |
$weixin = new WeixinApi('appid', 'secret'); | |
$ticket = $weixin->get_jsapi_ticket(); | |
echo $ticket; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment