Example #1
0
 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;
 }
Example #2
0
                     $wx->send_msg(array('userid' => (string) $fromUserName, 'appid' => (string) $agentID, 'msg' => '请您输入要查询的图片名称'));
                 }
                 if ($content != '2') {
                     $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;