Thinkphp5.0 的开发环境
微信配置和使用
private function createNonceStr($length = 16) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
/**
* 获取access_token
* @return array 返回access_token和有效期
*/
public function getAccessToken() {
if(!\think\Cache::get('access_token')){
$res = $this->http('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $this->config['appid'] . '&secret=' . $this->config['appsecret']);
if (!$res) {
$this->errorMsg = 'CURL超时';
return false;
}
$resp = json_decode($res,