全网整合营销服务商

营销型网站+SEO优化+关键词快排=一站式服务

免费咨询热线:15959292472

[晋城seo公司首推久澳]小程序实例:小程序客服发送图片信息的实现代码

  

本篇文章给大家带来的内容是关于小程序实例==◁:小程序客服发送图片信息的实现代码,有一定的参考价值▲☆◇★,有需要的朋友可以参考一下,希望对你有所帮助▷□•◇。[晋城seo公司首推久澳]
 

  

 /**
 * 发送客服消息接口
 */
 public function actionCustomService()
 {
 $data = file_get_contents('php▪…•://input'○▲=;)▲•; 
 $data = json_decode($data,true); 
 $qrcode_url = Yii::$app->params['gzh_qrcode'▪•●;]▽▼; 
 $openId = $data['■○▷;FromUserName']…●★◇; 
 $access_token = self◁■:▷△○:getAccessToken()•…●; 
 $url = 'https://api◆◆•▲.weixin◆★.qq=☆.com/cgi-bin/message/custom/send?access_token='●▲○;○★.$access_token; 
 $appid = Yii◁□…::$app->params['-•…■;miniAppid'●•;]; 
 $media_id = self-◁▷▲::getRedis("wx_material:$appid"◇=◁▲;◁=, 'media_id'△•;); 
 if (!$media_id) { 
 $material = self:◆▪:uploadImg($qrcode_url★-,$access_token); 
 if ($material) { 
 $redis = Yii::$app->☆●;redis; 
 $redis->hmset("wx_material:$appid"☆★;-=…, 'type', $material['type'=△▲;]◁▽•△, '▷-★△;media_id'•=△▷, $material['media_id'•△;]=◇, 'created_at', $material['created_at'])◆=…; 
 $redis->expire("☆▼☆;wx_material▼▷★▪:$appid"=●◁▽, 7200);
 } 
 $media_id = $material['media_id'];
 } 
 $data1 = [
 'touser' => $openId, 
 'msgtype' =>•-; '▽■-▼;image', 
 'image' => [
 'media_id' => $media_id,
 ],
 ]▲◁=◆; 
 $data1 = json_encode($data1,JSON_UNESCAPED_UNICODE)▼▲■; 
 $result = self○●::https_request($url◇=▷,$data1); 
 echo 'success'◆■☆○;
 }
 //上传素材到微信
 public static function uploadImg($img,$access_token)
 {
 $url = 'https◁□▼://api▲□…….weixin▲•.qq.com/cgi-bin/media/upload?access_token='.$access_token▷◁◇.'…△■;&type=image'●◁◇; 
 $fileName = time() . '☆☆★;▲○.jpg'; 
 $source = file_get_contents($img);
 file_put_contents('▪◆=./images/material/'•◁□;.$fileName,$source)◆▷□●; 
 if (class_exists('★◆◆;\CURLFile')) { 
 $josn = array('▪-◇▪;media' =>□▽●○; new \CURLFile(realpath("images/material/" . $fileName)))★▪■▼;
 } else { 
 $josn = array('media' => '@' . realpath("images/material/" . $fileName))▼□;
 }
 unlink('■▪./images/material/'.$fileName)-☆◁; 
 $result = self▪△★:◇●…:curl_post($url,$josn); 
 $result = json_decode($result★◆=,true); 
 return $result★▽•;
 }

 

  下面的都是通用代码

  

 //获取access_token
 public static function getAccessToken()
 {
 $appid = Yii::$app->params['●■…;miniAppid']; 
 $appsecret = Yii=▼•●::$app->params['miniSecret'△◆;]; 
 $url = 'https-△★://api…◆•.weixin.qq.com/cgi-bin/token?grant_type=client_credential&★•;appid='.$appid.'&secret='.$appsecret; 
 $result = self:…◆■:httpGet($url); 
 $access_token = json_decode($result,true)['access_token']; 
 return $access_token●…•;
 }
 //get方法获取内容
 private static function httpGet($url)
 {
 $curl = curl_init();
 curl_setopt($curl, CURLOPT_RETURNTRANSFER☆○◁, true)▲■;
 curl_setopt($curl□•◁, CURLOPT_TIMEOUT, 500)◇◆■▽;
 curl_setopt($curl▽○☆, CURLOPT_SSL_VERIFYPEER○◆▼□, 2);
 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST▼△•△, 2);
 curl_setopt($curl▼★▪-, CURLOPT_URL=•◆, $url); 
 $res = curl_exec($curl);
 curl_close($curl)▽•=▽; 
 return $res;
 }
 //http请求
 public static function https_request($url,$data=null)
 {
 $curl = curl_init();
 curl_setopt($curl•◁★,CURLOPT_URL,$url)▼▽;
 curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,FALSE);
 curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,FALSE)▽•; 
 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▲▷;
 }

 

  相关推荐:

  小程序中授权相册的解决办法(附代码)

  微信小程序实例:点击事件和长按事件的代码实现

  以上就是小程序实例:小程序客服发送图片信息的实现代码的详细内容,更多请关注久澳传媒编程栏目其它相关文章!09 2020.10 [徐州专业seo优化公司]ps怎么选中图层内容 ps选中图层内容的方法●▪:1、鼠标左键直接去选择图层, Layui教程 找对应图形的图层;2、将上方属性栏中【自由选择】前划上对勾-□,再点击图形;3、琼海市小程序开发哪家好按住CTRL键后●-,米泉市小程序制作公司鼠标左键单

[晋城seo公司首推久澳]小程序实例:小程序客服发送图片信息的实现代码

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。