...
|
...
|
@@ -180,56 +180,6 @@ class PersonalcenterController extends WeChatBaseController{ |
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 上传图片
|
|
|
*/
|
|
|
public function savePicture(){
|
|
|
|
|
|
$access_token=$this->getAccessToken();
|
|
|
$filepath = $_POST['mediaId'];
|
|
|
$str = 'uploads/'.date('YmdHis').time().rand('1000000','99999999').'.png';
|
|
|
$targetName = $str;
|
|
|
$access_token = $access_token['accessToken'];
|
|
|
$file = file_get_contents("http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=$access_token&media_id=$filepath");
|
|
|
file_put_contents($targetName,$file);
|
|
|
$msg["filename"] = '/'.$str;
|
|
|
return json_encode($msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getAccessToken() {
|
|
|
// access_token 应该全局存储与更新
|
|
|
// 获取数据库中的access_token
|
|
|
$token = Db::name('token') -> where('id',1) -> find();
|
|
|
// accessToken过期或不存在时
|
|
|
if($token['time'] + $token['expiresIn'] < time() || $token['accessToken'] == NULL){
|
|
|
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="."wxdf34ec2179e19b9a"."&secret="."133ced06db2a45843ab52abc691ee82d";
|
|
|
// 微信返回的信息
|
|
|
$returnData = json_decode($this->httpGet($url));
|
|
|
// 组装数据
|
|
|
$resData['accessToken'] = $returnData->access_token;
|
|
|
$resData['expiresIn'] = $returnData->expires_in;
|
|
|
$resData['time'] = time();
|
|
|
// 把数据存进数据库
|
|
|
Db::name('token') -> where('id',1) -> update($resData);
|
|
|
$res = $resData;
|
|
|
}else{
|
|
|
$res = $token;
|
|
|
}
|
|
|
return $res;
|
|
|
}
|
|
|
|
|
|
private function httpGet($url) {
|
|
|
$curl = curl_init();
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true );
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, 500 );
|
|
|
curl_setopt($curl, CURLOPT_URL, $url );
|
|
|
$res = curl_exec($curl);
|
|
|
curl_close($curl);
|
|
|
return $res;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
...
|
...
|
|