function handleImage($postObj) { //https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID $access_token = db_get_token_ticket(CFG_APPID, CFG_SECRET)["token"]; $mediaId = $postObj->MediaId; $url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id={$mediaId}"; $fileinfo = downloadWeixinFile($url); // $uploadPath = dirname(__FILE__) . "/upload/weixin/"; $tmpFile = time() . ".jpg"; saveWeixinFile($uploadPath . $tmpFile, $fileinfo["body"]); response_text($postObj, "图片上传完成"); }
function handleImage($postObj) { //https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID $access_token = db_get_token_ticket(CFG_APPID, CFG_SECRET)["token"]; $mediaId = $postObj->MediaId; $url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id={$mediaId}"; $fileinfo = downloadWeixinFile($url); // $uploadPath = dirname(__FILE__) . "/upload/weixin/"; $fileName = time() . ".jpg"; saveWeixinFile($uploadPath . $fileName, $fileinfo["body"]); response_text($postObj, "图片上传完成"); //保存图片信息 $params = array(array("" . $postObj->FromUserName, SQLSRV_PARAM_IN), array("" . $fileName, SQLSRV_PARAM_IN)); sp_execute("{call app_upload_image(?,?)}", $params); }
$status = ""; unset($_SESSION["ccl"]); if (isset($_REQUEST["canteenName"])) { //download image if (isset($_REQUEST["mediaId"])) { $mediaId = $_REQUEST["mediaId"]; //https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID $access_token = db_get_token_ticket(CFG_APPID, CFG_SECRET)["token"]; $url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id={$mediaId}"; $fileinfo = downloadWeixinFile($url); // $uploadPath = dirname(dirname(__FILE__)) . "/upload/shop/"; $tmpFile = "aaa.jpg"; $time = time(); $ext = ".jpg"; saveWeixinFile($uploadPath . $tmpFile, $fileinfo["body"]); my_image_resize($uploadPath . $tmpFile, $uploadPath . $time . $ext, 375, 300); } // $canteenName = $_REQUEST["canteenName"]; $canteenTel = $_REQUEST["canteenTel"]; $picurl = $time . $ext; $cid = 0; //创建餐厅,并建立绑定关系,设置成管理员 $longitude = $_REQUEST["longitude"]; $latitude = $_REQUEST["latitude"]; db_log("create canteen x:{$longitude}, y:{$latitude}, tel:{$canteenTel}"); $params = array(array(intval($_SESSION["uid"]), SQLSRV_PARAM_IN), array("" . $canteenName, SQLSRV_PARAM_IN), array("" . $canteenTel, SQLSRV_PARAM_IN), array("" . $picurl, SQLSRV_PARAM_IN), array("" . $longitude, SQLSRV_PARAM_IN), array("" . $latitude, SQLSRV_PARAM_IN), array($cid, SQLSRV_PARAM_OUT)); sp_execute("{call app_user_create_canteen(?,?,?,?,?,?,?)}", $params); $_SESSION["cid"] = $cid; $_SESSION["cname"] = $canteenName;
<?php session_start(); //启用session支持 include_once 'mcr_sc_fns.php'; require_once 'system/model/weixin.class.php'; $weixin = new class_weixin(); $mediaid = $_GET['mediaid']; //$mediaid=""; $access_token = $weixin->access_token; $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" . $access_token . "&media_id=" . $mediaid; $fileInfo = downloadWeixinFile($url); $filename = "down_image.jpg"; // echo $url; // return; saveWeixinFile($filename, $fileInfo["body"]); function downloadWeixinFile($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_NOBODY, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $package = curl_exec($ch); // echo $package; // echo "==================="; $httpinfo = curl_getinfo($ch); // echo @implode(';',$httpinfo); curl_close($ch); $imageAll = array_merge(array('header' => $httpinfo), array('body' => $package));
$sql_ing = "select valid from wx_activity_interact_project where id=" . $projectId; $res_ing = $db->getrow($sql_ing); if ($res_ing['valid']) { //正在进行 require_once '../../../common/php/configSelf.php'; $access_token = getAccessToken($appIdSelf, $appSecretSelf); $mediaid = $_GET['media']; $media = explode(";", $mediaid); $medianame = null; foreach ($media as $key_media => $val_media) { if ($val_media != null) { $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" . $access_token . "&media_id=" . $val_media; $fileInfo = downloadWeixinFile($url); //var_dump($fileInfo); $filename[$key_media] = "../../../common/upload_image/" . $val_media . ".jpg"; saveWeixinFile($filename[$key_media], $fileInfo['body']); $medianame = $medianame . $filename[$key_media] . ";"; } } $join = array(); //用于数据库的插入 //查询图片互动审核功能是否开启 $sql_audit = "select flag from wx_audit where name='pictureInteract'"; $res_audit = $db->getrow($sql_audit); $join_pre['audit'] = $res_audit['flag']; //0:未开启;1:开启 //查询该活动项允许一次同时上传的图片数量最大值 $sql_size = "select num from wx_activity_interact_project where id=" . $projectId; $res_size = $db->getrow($sql_size); $join_pre['num'] = $res_size['num']; $join['projectId'] = $projectId;
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . AppID . "&secret=" . AppSecret; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $jsoninfo = json_decode($output, true); $access_token = $jsoninfo["access_token"]; /* 获取单个元素(根据id) */ @($b = $lastid); if ($b == @$lastid) { $url1 = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" . $access_token . "&media_id=" . "{$imgid}"; $ret = https_request($url1, null); saveWeixinFile("update/{$b}.jpg", $ret); //下载后好的文件名 } function saveWeixinFile($filename, $filecontent) { $local_file = fopen($filename, 'w'); if (false !== $local_file) { if (false !== fwrite($local_file, $filecontent)) { fclose($local_file); } } /*if (is_writable($filename)) { echo file_put_contents($filename, $filecontent); } else {