/** * to config content data and send to target * @param array $data - content data in array * (format like array( * "first"=>array("value"=>"","color"=>""), * "remark"=>array("value"=>"","color"=>"")) * ) * @return data received after posting */ public function send($data) { $this->body['data'] = $data; $json = json_encode($this->body); $client = new HttpClient("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$this->access_token}"); $client->setParameter($json); return $client->post(); }
public function send($content) { $data = array("touser" => $this->openid, "msgtype" => "text", "text" => array("content" => urlencode($content))); $data = urldecode(json_encode($data)); $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$this->access_token}"; $client = new HttpClient($url); $client->setParameter($data); return $client->post(); }
public function create($statement) { $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$this->access_token}"; if (is_array($statement)) { include dirname(__FILE__) . '/../util/arr_urlencode.php'; $statement = arr_urlencode($statement); $statement = urldecode(json_encode($statement)); } $client = new HttpClient($url); $client->setParameter($statement); return $client->post(); }
/** * to get the short url by transforming * @param string $url - long url * @return string - short url (or boolean false if fail) */ public function get($url) { if ($this->access_token) { $client = new HttpClient("https://api.weixin.qq.com/cgi-bin/shorturl?access_token={$this->access_token}"); $client->setParameter(array('action' => 'long2short', 'long_url' => $url)); $stream = json_decode($client->post()); if (isset($stream->short_url)) { return $stream->short_url; } } return false; }