コード例 #1
0
ファイル: ws_ErpToWx_TextImg.php プロジェクト: wuya1986/php
 public function zfunc($zimgname, $zimgurl)
 {
     $wx = new weixin();
     $access_token = $wx->get_tk();
     //下载图片,转发上传到微信临时素材库
     $imageData = $wx->httpGet($zimgurl);
     $fp = fopen(dirname(__FILE__) . "/" . $zimgname . ".jpg", 'w+');
     fwrite($fp, $imageData);
     fclose($fp);
     $filepath = dirname(__FILE__) . "/" . $zimgname . ".jpg";
     $filedata = array("media" => "@" . $filepath);
     //Linux绝对路径
     $url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={$access_token}&type=image";
     $res = $wx->httpPost($url, $filedata);
     $res = json_decode($res);
     $media_id = $res->media_id;
     $wx->send_img(array('userid' => 'plustree', 'appid' => '2', 'mediaid' => $media_id));
     $b = "return seccess";
     return $b;
 }
コード例 #2
0
ファイル: index2.php プロジェクト: wuya1986/php
                     $access_token = $wx->get_tk();
                     //下载图片,转发上传到微信临时素材库
                     $zimgurl = "http://192.168.5.134:7777/static/DEV/" . $content . ".jpg";
                     $imageData = $wx->httpGet($zimgurl);
                     if (stripos($imageData, "Not Found") == FALSE) {
                         $fp = fopen(dirname(__FILE__) . "/" . $content . ".jpg", 'w+');
                         fwrite($fp, $imageData);
                         fclose($fp);
                         $filepath = dirname(__FILE__) . "/" . $content . ".jpg";
                         $filedata = array("media" => "@" . $filepath);
                         //Linux绝对路径
                         $url = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token={$access_token}&type=image";
                         $res = $wx->httpPost($url, $filedata);
                         $res = json_decode($res);
                         $media_id = $res->media_id;
                         $wx->send_img(array('userid' => (string) $fromUserName, 'appid' => (string) $agentID, 'mediaid' => (string) $media_id));
                         unlink($content . ".jpg");
                     } else {
                         $wx->send_msg(array('userid' => (string) $fromUserName, 'appid' => (string) $agentID, 'msg' => '此图片不存在!'));
                     }
                 }
             }
         }
     }
 }
 if ($msgType == "event") {
     $event = $res_xmlstr->Event;
     $eventKey = $res_xmlstr->EventKey;
     $redis->delete("type");
     //$msgId = $res_xmlstr->MsgId;
 }