/** * 下载多媒体文件 * @param $mediaId 多媒体ID * @return 头信息如下 * * HTTP/1.1 200 OK * Connection: close * Content-Type: image/jpeg * Content-disposition: attachment; filename="MEDIA_ID.jpg" * Date: Sun, 06 Jan 2013 10:20:18 GMT * Cache-Control: no-cache, must-revalidate * Content-Length: 339721 * curl -G "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID" */ public function download($mediaId) { $Curl = new Curl(); $params['access_token'] = $this->accessToken; $params['media_id'] = $mediaId; $res = $Curl->callApi($this->downloadMediaURL, $params, 'GET'); return $res; }
public function curl() { $Curl = new Curl(); $url = "https://api.weixin.qq.com/cgi-bin/token"; $params['grant_type'] = 'client_credential'; $params['appid'] = 'wx25dc2ed8888b623e'; $params['secret'] = 'de7f2f20fcb0870a9c560f3879f62d9c'; $res = $Curl->callApi($url, $params); // $res = $Curl->fetch("http://www.hao123.com"); dump($res); }
/** * 获取Access Token * @return null | string */ private function _fetchAccessToken() { $Curl = new Curl(); $params['grant_type'] = 'client_credential'; $params['appid'] = get_opinion('Weixin_appid'); $params['secret'] = get_opinion('Weixin_secret'); $accessToken = $Curl->callApi($this::$AccessTokenURL, $params, 'GET'); if (!isset($accessToken['access_token'])) { Log::write("Error occurred when call AccessToken Api"); return null; } return $accessToken['access_token']; }
/** * 图文 - 先调用self::newsItem()再调用本方法 * @param $tousername * @param $item 数组,每个项由self::newsItem()返回 * @return string */ public function news($tousername, $item) { $Curl = new Curl(); //开始 $template = array('touser' => $tousername, 'msgtype' => 'news', 'news' => array('articles' => $item)); $template = json_encode($template); return $Curl->callApi($this->msgUrl, $template, 'POST'); }
/** * 获取关注者列表 * @param string|\Weixin\Util\第一个拉取的OPENID $next_openid 第一个拉取的OPENID,不填默认从头开始拉取 * @return JSON {"total":2,"count":2,"data":{"openid":["","OPENID1","OPENID2"]},"next_openid":"NEXT_OPENID"} */ public function getFansList($next_openid = '') { $Curl = new Curl(); if (empty($next_openid)) { $queryUrl = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token=' . $this->accessToken; } else { $queryUrl = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token=' . $this->accessToken . '&next_openid=' . $next_openid; } $data = ''; return $Curl->callApi($queryUrl, $data, 'GET'); }
public function getTokenByCode($code) { $this->accessTokenUrl .= "client_id={$this->appKey}&client_secret={$this->appSecret}&grant_type=authorization_code&code={$code}&redirect_uri={$this->callbackUrl}"; return (array) json_decode(Curl::getInstance()->curl_post($this->accessTokenUrl, [])); }
/** * 获取素材列表 * @throws \yii\web\HttpException */ public function materialList() { $url = self::MATERIAL_LIST . $this->getAccessToken(); $param['type'] = 'news'; $param['offset'] = 0; $param['count'] = 20; $paramJson = json_encode($param); $result = Curl::getInstance()->curl_post($url, $paramJson); $result = json_decode($result); // var_dump($result); return $result; }
/** * 删除菜单 * @return bool|mixed|string */ public function delMenu() { $Curl = new Curl(); $params['access_token'] = $this->accessToken; $res = $Curl->callApi($this->delMenuUrl, $params, 'GET'); return $res; }