微信公众号推送图片php,php 微信上传图片 客服发送图片

php 微信上传图片 客服发送图片

public function _getAccessToken()

{

$where = array(‘token’ => $this->token);

$this->thisWxUser = M(‘Wxuser’)->where($where)->find();

// import(‘@.ORG.apiOauth’);

$apiOauth = new apiOauth();

$access_token = $apiOauth->update_authorizer_access_token($this->thisWxUser[‘appid’]);

return $access_token;

}

function upload_meterial($file_info,$access_token){

$url=”https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={$access_token}&type=image”;

$ch1 = curl_init ();

$timeout = 5;

$data= array(“media”=>”@{$file_info}”);

curl_setopt ( $ch1, CURLOPT_URL, $url );

curl_setopt ( $ch1, CURLOPT_POST, 1 );

curl_setopt ( $ch1, CURLOPT_RETURNTRANSFER, 1 );

curl_setopt ( $ch1, CURLOPT_CONNECTTIMEOUT, $timeout );

curl_setopt ( $ch1, CURLOPT_SSL_VERIFYPEER, FALSE );

curl_setopt ( $ch1, CURLOPT_SSL_VERIFYHOST, false );

curl_setopt ( $ch1, CURLOPT_POSTFIELDS, $data );

$result = curl_exec ( $ch1 );

curl_close ( $ch1 );

if(curl_errno()==0){

$result=json_decode($result,true);

//var_dump($result);

return $result[‘media_id’];

}else {

return false;

}

}

public function curl_post($url, $data = null)

{

//创建一个新cURL资源

$curl = curl_init();

//设置URL和相应的选项

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);

//执行curl,抓取URL并把它传递给浏览器

$output = curl_exec($curl);

//关闭cURL资源,并且释放系统资源

curl_close($curl);

return $output;

}

public function sendimg($filename){

$access_token = $this->_getAccessToken();

$resmedia_id = $this->upload_meterial($filename,$access_token);

if($resmedia_id){

//发送

$FromUserNamet = “o7pw-waUVRGw72OhxZ8v9qpVEUPM”;

$data='{“touser”: “‘.$FromUserNamet.'”,”msgtype”: “image”,”image”: {“media_id”: “‘.$resmedia_id.'”}}’;

$url2 = “https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=”.$access_token;

$res = $this->curl_post($url2,$data);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值