/** * 根据账户ID获得access token 如果过期 再重新获取一下 * @param $accountID 账号ID * @param $filePath 文件绝对路径 * @return $accsess_token token */ static function uploadWxMedia($accountID, $type, $filePath) { //允许的类型及大小(KB) $access_media = array('image' => 128, 'voice' => 256, 'video' => 1024, 'thumb' => 64); switch (true) { case !isset($access_media[$type]): throw new THttpException("media type not allow"); break; case !file_exists($filePath): throw new THttpException("file not exists"); break; case filesize($filePath) >= $access_media[$type] * 1024: throw new THttpException("file is too large"); break; } $token = WxApi::getAccessToken($accountID); $postData = array('media' => '@' . $filePath); $url = str_replace('[TOKEN]', $token, WX_UPLOAD_MEDIA_URL); $url = str_replace('[TYPE]', $type, $url); $request = Yii::app()->curl->run($url, $postData); $aResponse = WeixinApi::parseResponse($request, __FILE__, __LINE__); $model_media = new UploadMediaFile(); $model_media->accountid = $accountID; $model_media->mediaid = $aResponse['media_id']; $model_media->create_time = $aResponse['created_at']; $model_media->filepath = $filePath; $model_media->type = $type; $model_media->expire_time = $aResponse['created_at'] + 3600 * 24 * 3; $model_media->save(); return $model_media->ID; }
public function actionTest() { return; $request = Yii::app()->curl->run("http://clk.optaim.com/event.ng/Type=click&FlightID=201309&TargetID=sohu&Values=4960caa5,d64a93f7,0bd7d879,040f2666&AdID=1023788"); var_dump($request->getInfo()); $at = WxApi::getAccessToken(1); $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$at}"; $data = ' { "button":[ { "name":"车型选择", "sub_button":[ { "type":"view", "name":"全部车型", "url":"http://weixin.optaim.com/tpl/allcars.html" }, { "type":"view", "name":"尊选二手车", "url":"http://weixin.optaim.com/tpl/scar.html" }, { "type":"view", "name":"照片展示", "url":"http://weixin.optaim.com/tpl/pics.html" } ] }, { "name":"在线服务", "sub_button":[ { "type":"view", "name":"车主关怀", "url":"http://weixin.optaim.com/tpl/care.html" }, { "type":"view", "name":"预约保养", "url":"http://weixin.optaim.com/tpl/baoyang.html" }, { "type":"click", "name":"预约试驾", "key":"14_1_6" }] }, { "type":"view", "name":"进入官网", "url":"http://weixin.optaim.com/tpl/auto.html" }] } '; $a = Yii::app()->curl->run($url, $data); var_dump($a->getBody()); /* $abc = array('app_id'=>'1922874','app_secret'=>'40eae2780e80243bf0324b4557ee2fd8'); $request = Yii::app()->curl->run("http://adp.optaim.com/api/auth/access_token", $abc); $date = $request->getBody(); $a = json_decode($date, true); $abc = array('date'=>'2014-04-08','access_token'=>'4bf4ea6f23ef1df5df7f18878237752e9dac199ca42dced5c446ccf25eb5919a4ee19d228e7c844e26390a35b25d19d1789013c60cd2f6508f39413025782322'); $request = Yii::app()->curl->run("http://adp.optaim.com/api/report/hour", $abc); var_dump($request->getBody()); */ }