public
function
uploadImg(
$imgUrl
){
$TOKEN
=
$this
->getAccessToken();
$URL
=
'http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token='
.
$TOKEN
.
'&type=image'
;
$data
=
array
(
'media'
=>
'@'
.
$imgUrl
);
$result
=
$this
->curl_post(
$URL
,
$data
);
$data
= @json_decode(
$result
,true);
return
$data
[
'media_id'
];
}
public
function
getAccessToken(){
$url
=
'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxe574b1bd35d7d4da&secret=d4624c36b6795d1d99dcf0547af5443d'
;
$result
= json_decode(
$this
->curlGet(
$url
),true);
return
$result
[
'access_token'
];
}
function
curl_post(
$url
,
$data
= null)
{
$curl
= curl_init();
curl_setopt(
$curl
, CURLOPT_URL,
$url
);
if
(!
empty
(
$data
)){
curl_setopt(
$curl
, CURLOPT_POST, 1);
curl_setopt(
$curl
, CURLOPT_POSTFIELDS,
$data
);
}
curl_setopt(
$curl
, CURLOPT_RETURNTRANSFER, 1);
$output
= curl_exec(
$curl
);
curl_close(
$curl
);
return
$output
;
}