Пример #1
0
 /**
  * 上传文件
  * @param string $type
  * @param string $fileRealPath
  */
 public function upload($type = 'image', $fileRealPath)
 {
     $types = array('image', 'voice', 'video', 'file');
     if (in_array($type, $types)) {
         $host = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s";
         $url = sprintf($host, $this->get_accesstoken('access_token'), $type);
         if (version_compare(PHP_VERSION, '5.5.0', '<')) {
             $data = array('media' => "@{$fileRealPath}");
         } else {
             $fileName = basename($fileRealPath);
             $finfo = finfo_open(FILEINFO_MIME_TYPE);
             $mimeType = finfo_file($finfo, $fileRealPath);
             $data['media'] = new \CurlFile($fileRealPath, $mimeType, $fileName);
         }
         $info = \Core\Curl::post($url, $data);
         $response = json_decode($info->response, true);
         if (!empty($response['media_id'])) {
             return $response['media_id'];
         }
         if (!empty($response['thumb_media_id'])) {
             return $response['thumb_media_id'];
         }
     } else {
         throw new \Exception('upload file type is not vaild!');
     }
     return FALSE;
 }
Пример #2
0
 /**
  * 回复客服消息,消息使用json格式化
  * 
  * @param json $params
  */
 public function reply($params)
 {
     $host = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=%s";
     $url = sprintf($host, $this->get_accesstoken());
     $info = \Core\Curl::post($url, $params);
     return json_decode($info->response, true);
 }
Пример #3
0
 /**
  * 发送消息请求
  * @param string $access_token
  * @param json $message
  */
 protected function push($message)
 {
     $host = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s';
     $info = \Core\Curl::post(sprintf($host, $this->get_accesstoken()), $message);
     $respone = json_decode($info->response, true);
     if (isset($respone['errcode']) && $respone['errcode'] == 0) {
         return $respone;
     }
     return FALSE;
 }
Пример #4
0
 /**
  * 创建菜单
  * @param json $params
  */
 public function create($params)
 {
     $host = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s';
     $url = sprintf($host, $this->get_accesstoken());
     $info = \Core\Curl::post($url);
     $response = json_decode($info->response, true);
     if ($response['errcode'] == 0) {
         return $response;
     }
     return false;
 }
Пример #5
0
 /**
  * 创建菜单
  * @param json $params
  */
 public function create($params)
 {
     $host = 'https://qyapi.weixin.qq.com/cgi-bin/menu/create?access_token=%s&agentid=0';
     $url = sprintf($host, $this->get_accesstoken());
     $info = \Core\Curl::post($url, $params);
     $response = json_decode($info->response, true);
     if (isset($response['errcode']) && $response['errcode'] == '0') {
         return TRUE;
     }
     return $response['errmsg'];
 }
Пример #6
0
 /**
  * 摇一摇,周边获取用户信息
  * @param bool $need_poi
  */
 public function shake_info($need_poi = false)
 {
     if (empty($_GET['ticket'])) {
         return false;
     }
     $ticket = $_GET['ticket'];
     $host = "https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=%s";
     $url = sprintf($host, $this->get_accesstoken());
     $params = array('ticket' => $ticket);
     if ($need_poi) {
         $params['need_poi'] = 1;
     }
     $info = \Core\Curl::post($url, json_encode($params));
     return json_decode($info->response, true);
 }
Пример #7
0
 /**
  * 核销卡券
  * @param $card_id 卡券ID
  * @param $code 自定义编码
  */
 public function consumption_card($card_id, $code = '')
 {
     $host = 'https://api.weixin.qq.com/card/code/consume?access_token=%s';
     $url = $url = sprintf($host, $this->get_accesstoken());
     $params = array('card_id' => $card_id);
     if (!empty($code)) {
         $params['code'] = $code;
     }
     $info = \Core\Curl::post($url, json_encode($params));
     $response = json_decode($info->response, true);
     log_message(var_export($response, true), var_export($params, true));
     if ($response['errcode'] == 0) {
         return $response;
     }
     return false;
 }
Пример #8
0
 /**
  * 发送请求
  */
 public function send()
 {
     $host = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack';
     $option = array(CURLOPT_SSLCERT => $this->cert, CURLOPT_SSLKEY => $this->key, CURLOPT_CAINFO => $this->ca, CURLOPT_HTTPHEADER => array('Content-Type: text/xml'));
     $xml = $this->create_xml();
     $rs = \Core\Curl::post($host, $xml, $option);
     $message = $this->xml2arr($rs->response);
     log_message(var_export($message, true));
     return $message;
 }
Пример #9
0
 /**
  * 更新用户信息
  * @param array $user_info
  * 
  * @code
  * $user_info = array(
  *    'userid' => '',
  *    'name' => '',
  *    'department' => '',
  *    'position' => '',
  *    'mobile' => '',
  *    'gender' => '',
  *    'tel' => '',
  *    'email' => '',
  *    'weixinid' => '',
  * );
  * @encode
  */
 public function update_member($user_info)
 {
     $host = "https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=%s";
     $url = sprintf($host, $this->get_accesstoken());
     $info = \Core\Curl::post($url, json_encode($user_info));
     $respone = json_decode($info->response, true);
     if (isset($respone['errcode']) && $respone['errcode'] == '0') {
         return TRUE;
     }
     return FALSE;
 }