2 chenkaipin chenkaipin 于 2017.09.20 10:11 提问

PHP 7.0 下微信图文发布脚本参考

public function upload($thumbfilename,$type="image")
{

  if(!$this->access_token && !$this->checkAuth()) return false;
    $data['media'] = new CURLFile($thumbfilename);
  $result = curlRequest(self::API_URL_PREFIX.self::UPLOAD_URL.'access_token='.$this->access_token."&type=".$type, $data, 'POSTFILE','','',10, 60 );
  if($result)
  {
   $jsonArr = json_decode($result, true);
   if(!$jsonArr || (isset($jsonArr['errcode']) && $jsonArr['errcode'] > 0)) 
   {
    $this->error($jsonArr);
   }
   else return $jsonArr;
  }
  return false;

}
public function uploadNews($thumb_media_id,$author,$title,$content,$content_source_url,$digest="",$show_cover_pic=1)
{
if(!$this->access_token && !$this->checkAuth()) return false;
$content = urlencode(htmlspecialchars(str_replace("\"","'",$content)));

  $data = '
  {
"articles": [
    {
        "thumb_media_id": "'.$thumb_media_id.'",
        "author": "'.$author.'",
        "title": "'.$title.'",
        "content_source_url": "'.$content_source_url.'",
        "content": "'.$content.'",
        "digest": "'.$digest.'",
        "show_cover_pic": "'.$show_cover_pic.'"
    }
]
}
';
$data=json_encode($data);
    $end_data= urldecode($data);
    $end_data= htmlspecialchars_decode($end_data);
  $result = curlRequest(self::API_URL_PREFIX.self::UPLOADNEWS_URL.'access_token='.$this->access_token, $end_data, 'post');
  if($result)
  {
   $jsonArr = json_decode($result, true);
   if(!$jsonArr || (isset($jsonArr['errcode']) && $jsonArr['errcode'] > 0)) 
   {
    $this->error($jsonArr);
    error_log(print_r($jsonArr,1));
  }
   else return $jsonArr;
  }
  return false;

}
public function sendAll($tag_id,$media_id)
{
if(!$this->access_token && !$this->checkAuth()) return false;
if (!$media_id || !$tag_id) return false;
$data = array();
/*
{
"filter":{
"is_to_all":false,
"tag_id":2
},
"mpnews":{
"media_id":"123dsdajkasd231jhksad"
},
"msgtype":"mpnews",
"send_ignore_reprint":0
}*/
$data['filter'] = array('is_to_all' =>false,'tag_id' =>$tag_id);
$data['mpnews'] = array('media_id' =>$media_id);
$data['msgtype'] = "mpnews";
$data['send_ignore_reprint'] = 0 ;
$result = curlRequest(self::API_URL_PREFIX.self::SENDALL_URL.'access_token='.$this->access_token, $this->jsonEncode($data), 'post');
if($result)
{
$jsonArr = json_decode($result, true);
if(!$jsonArr || (isset($jsonArr['errcode']) && $jsonArr['errcode'] > 0))
{
$this->error($jsonArr);
error_log(print_r($jsonArr,1));
}
else return $jsonArr;
}
return false;

}

Csdn user default icon
上传中...
上传图片
插入图片