示例#1
0
 public static function long2short($url)
 {
     $url = 'https://api.weixin.qq.com/cgi-bin/shorturl?access_token=' . AccessToken::getAccessToken();
     $data = array('action' => 'long2short', 'long_url' => $url);
     $res = Curl::httpGet($url, $data);
     return Error::isError($res) ? false : $res['short_url'];
 }
示例#2
0
 public static function getIp()
 {
     $accessToken = AccessToken::getAccessToken();
     $url = 'https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=' . $accessToken;
     $res = Curl::httpGet($url);
     return Error::isError($res) ? false : $res['ip_list'];
 }
示例#3
0
 public static function getTemplateId($template_id_short)
 {
     $url = 'https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=' . AccessToken::getAccessToken();
     $data = array('template_id_short' => $template_id_short);
     $res = Curl::httpGet($url, $data);
     return Error::isError($res) ? false : $res['template_id'];
 }
示例#4
0
 public static function uploadNews($articles)
 {
     /* 传入data实例
        $articles[] = array(
            'thumb_media_id'=> $media_id,
            'author'=> '天王盖地虎',
            'title'=> '这个我的测试消息',
            'content_source_url'=> 'our-class.cn',
            'content'=> '这是一个图文摘要',
            'digest'=> '',
            'show_cover_pic'=> 1,
        );
        $articles[] = array(
            'thumb_media_id'=> $media_id,
            'author'=> '天王盖地虎',
            'title'=> '这个我的测试消息',
            'content_source_url'=> 'our-class.cn',
            'content'=> '这是一个图文摘要',
            'digest'=> '',
            'show_cover_pic'=> 1,
        );
        */
     $url = 'https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=' . AccessToken::getAccessToken();
     if (count($articles) > 10) {
         href('文章总数大于10');
         return false;
     }
     $data = array('articles' => $articles);
     $res = Curl::httpGet($url, $data);
     return Error::isError($res) ? false : $res['media_id'];
 }
示例#5
0
 static function getuser($begin_date, $end_date, $summary = true)
 {
     if ($summary) {
         $url = 'https://api.weixin.qq.com/datacube/getusersummary?access_token=' . AccessToken::getAccessToken();
     } else {
         $url = 'https://api.weixin.qq.com/datacube/getusercumulate?access_token=' . AccessToken::getAccessToken();
     }
     $data = array('begin_date' => $begin_date, 'end_date' => $end_date);
     $res = Curl::httpGet($url, $data);
     return Error::isError($res) ? false : $res;
 }
示例#6
0
 public static function setImage($file, $kf_account)
 {
     if (!file_exists($file)) {
         href('文件不存在');
         return false;
     }
     $url = 'http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=' . AccessToken::getAccessToken() . '&kf_account=' . $kf_account;
     $data = array('filename' => $file);
     $data = array("media" => "@" . $file, 'form-data' => $data);
     $res = Curl::httpGet($url, $data);
     return Error::isError($res) ? false : $res;
 }
示例#7
0
 public function query($url)
 {
     $result = array('status' => 0, 'data' => '', 'err' => '');
     $res = Curl::httpGet($this->_url . $url, false, true);
     if ($res['header']['http_code'] == 200) {
         $result['status'] = 1;
         $result['data'] = $res['body'];
     } elseif ($res['err'] != '') {
         throw new \Exception($res['err']);
     } else {
         $result['status'] = 0;
         $result['data'] = $res['body'];
     }
     return $result;
 }
示例#8
0
 public function get($id, $source = false)
 {
     $result = array('status' => 0, 'data' => '', 'err' => '');
     $url = $source == false ? $this->_url . $this->_name . '/' . $id : $this->_url . $this->_name . '/' . $id . '/_source';
     $res = Curl::httpGet($url, false, true);
     if ($res['header']['http_code'] == 200) {
         $result['status'] = 1;
         $result['data'] = $res['body'];
     } elseif ($res['err'] != '') {
         throw new \Exception($res['err']);
     } else {
         $result['status'] = 0;
         $result['data'] = $res['body'];
     }
     return $result;
 }
示例#9
0
 public static function addMedia($file, $type = 'image', $info = array())
 {
     $url = 'https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=' . AccessToken::getAccessToken();
     if (!file_exists($file)) {
         href('文件不存在');
         exit;
     }
     $data = array('filename' => $file);
     if ($type == 'video') {
         $description = array('title' => $info['title'], 'introduction' => $info['introduction']);
         $data = array("media" => "@" . $file, 'form-data' => $data, 'type' => $type, 'description' => $description);
     } else {
         $data = array("media" => "@" . $file, 'form-data' => $data, 'type' => $type);
     }
     $res = Curl::httpGet($url, $data);
     return Error::isError($res) ? false : $res;
 }
示例#10
0
 private static function getJsApiTicket()
 {
     $mmc = memcache_init();
     $ticketInfo = @$mmc->get('ticket');
     if (isset($ticketInfo['ticket']) && time() - $ticketInfo['expires'] < 7000) {
         return $ticketInfo['ticket'];
     }
     $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=" . AccessToken::getAccessToken();
     $res = Curl::httpGet($url);
     if (Error::isError($res)) {
         exit;
     }
     $data['ticket'] = $res['ticket'];
     $data['expires'] = time();
     //存入Memcache
     $mmc->set('ticket', $data, 7200);
     return $res['ticket'];
 }
示例#11
0
 public static function getAccessToken()
 {
     $mmc = memcache_init();
     $accessTokenArr = @$mmc->get('accessToken');
     $accessToken = $accessTokenArr['access_token'];
     if (!isset($accessTokenArr['access_token']) || time() - $accessTokenArr['expires'] > 7200 - 100) {
         $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&' . 'appid=' . getConfig('WX')['appID'] . '&secret=' . getConfig('WX')['appsecret'];
         $res = Curl::httpGet($url);
         if (Error::isError($res)) {
             return false;
         }
         $res['expires'] = time();
         //存入Memcache
         $mmc->set('accessToken', $res, 7200);
         $accessToken = $res['access_token'];
     }
     return $accessToken;
 }
示例#12
0
 /**
  * 调用外部url
  * @param $queryUrl
  * @param $param
  * @param string $method
  * @return bool|mixed
  */
 public static function callWebServer($queryUrl, $param, $method = 'get')
 {
     if (empty($queryUrl)) {
         return false;
     }
     $method = strtolower($method);
     $ret = '';
     $param = empty($param) ? array() : $param;
     $curlObj = new Curl();
     if ($method == 'get') {
         $ret = $curlObj->httpGet($queryUrl, GAME_URL, $param);
     } elseif ($method == 'post') {
         $ret = $curlObj->httpPost($queryUrl, GAME_URL, $param);
     }
     if (!empty($ret)) {
         return json_decode($ret, true);
     }
     return true;
 }
示例#13
0
 public static function preview($type, $touser, $media_id, $content = NULL)
 {
     $url = 'https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=' . AccessToken::getAccessToken();
     switch ($type) {
         case 'text':
             $data = '{
                         "touser":"******",
                         "text":{
                                "content":"' . $content . '"
                                },
                         "msgtype":"text"
                     }';
             break;
         case 'mpnews':
             $data = '{
                        "touser":"******",
                        "mpnews":{
                                 "media_id":"' . $media_id . '"
                                  },
                        "msgtype":"mpnews"
                     }';
             break;
         case 'voice':
             $data = '{
                        "touser":"******",
                        "voice":{
                                 "media_id":"' . $media_id . '"
                                  },
                        "msgtype":"voice"
                     }';
             break;
         case 'image':
             $data = '{
                        "touser":"******",
                        "image":{
                                 "media_id":"' . $media_id . '"
                                  },
                        "msgtype":"image"
                     }';
             break;
         case 'mpvideo':
             $data = '{
                        "touser":"******",
                        "mpvideo":{
                                 "media_id":"' . $media_id . '"
                                  },
                        "msgtype":"mpvideo"
                     }';
             break;
         case 'wxcard':
             $data = '{ "touser":"******",
                       "wxcard":{
                                "card_id":"' . $media_id . '",
                                 "card_ext": "{"code":"","openid":"","timestamp":"1402057159","signature":"017bb17407c8e0058a66d72dcc61632b70f511ad"}"
                                 },
                       "msgtype":"wxcard"
                     }';
             break;
         default:
             href('迷茫了');
             exit;
     }
     $res = Curl::httpGet($url, $data);
     return Error::isError($res) ? false : $res['msg_id'];
 }
示例#14
0
 public function getAll()
 {
     $res = Curl::httpGet($this->_url . '_cat/indices/', false, true);
     if ($res['header']['http_code'] == 200) {
         $result['status'] = 1;
         $result['data'] = $res['body'];
     } elseif ($res['err'] != '') {
         throw new \Exception($res['err']);
     } else {
         $result['status'] = 0;
         $result['data'] = $res['body'];
     }
     return $result;
 }
示例#15
0
 public static function getConfig()
 {
     $url = 'https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=' . AccessToken::getAccessToken();
     $res = Curl::httpGet($url);
     return Error::isError($res) ? false : $res;
 }
示例#16
0
 public static function getUserList($next_openid = NULL)
 {
     $url = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token=' . AccessToken::getAccessToken() . '&next_openid=' . $next_openid;
     $res = Curl::httpGet($url);
     return Error::isError($res) ? false : $res;
 }
示例#17
0
 private static function doCurl($data)
 {
     self::init();
     $res = Curl::httpGet(self::$url, $data);
     return Error::isError($res) ? false : true;
 }