|
|
@ -1,16 +1,32 @@
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
namespace LaneWeChat\Core;
|
|
|
|
namespace LaneWeChat\Core;
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 发送主动响应
|
|
|
|
|
|
|
|
* Created by Lane.
|
|
|
|
|
|
|
|
* User: lane
|
|
|
|
|
|
|
|
* Date: 13-12-29
|
|
|
|
|
|
|
|
* Time: 下午5:54
|
|
|
|
|
|
|
|
* Mail: lixuan868686@163.com
|
|
|
|
|
|
|
|
* Website: http://www.lanecn.com
|
|
|
|
|
|
|
|
*/
|
|
|
|
class ResponseInitiative{
|
|
|
|
class ResponseInitiative{
|
|
|
|
|
|
|
|
|
|
|
|
protected static $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=';
|
|
|
|
protected static $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=';
|
|
|
|
|
|
|
|
|
|
|
|
protected static $action = 'POST';
|
|
|
|
protected static $action = 'POST';
|
|
|
|
public static function text($tousername, $content){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @descrpition 文本
|
|
|
|
|
|
|
|
* @param $tousername
|
|
|
|
|
|
|
|
* @param $content 回复的消息内容(换行:在content中能够换行,微信客户端就支持换行显示)
|
|
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static function text($tousername, $content){
|
|
|
|
|
|
|
|
//获取ACCESS_TOKEN
|
|
|
|
$accessToken = AccessToken::getAccessToken();
|
|
|
|
$accessToken = AccessToken::getAccessToken();
|
|
|
|
self::$queryUrl = self::$queryUrl.$accessToken;
|
|
|
|
self::$queryUrl = self::$queryUrl.$accessToken;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//开始
|
|
|
|
$template = array(
|
|
|
|
$template = array(
|
|
|
|
'touser'=>$tousername,
|
|
|
|
'touser'=>$tousername,
|
|
|
|
'msgtype'=>'text',
|
|
|
|
'msgtype'=>'text',
|
|
|
@ -23,6 +39,12 @@ class ResponseInitiative{
|
|
|
|
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
|
|
|
|
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @descrpition 图片
|
|
|
|
|
|
|
|
* @param $tousername
|
|
|
|
|
|
|
|
* @param $mediaId 通过上传多媒体文件,得到的id。
|
|
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static function image($tousername, $mediaId){
|
|
|
|
public static function image($tousername, $mediaId){
|
|
|
|
//获取ACCESS_TOKEN
|
|
|
|
//获取ACCESS_TOKEN
|
|
|
|
$accessToken = AccessToken::getAccessToken();
|
|
|
|
$accessToken = AccessToken::getAccessToken();
|
|
|
@ -40,6 +62,12 @@ class ResponseInitiative{
|
|
|
|
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
|
|
|
|
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @descrpition 语音
|
|
|
|
|
|
|
|
* @param $tousername
|
|
|
|
|
|
|
|
* @param $mediaId 通过上传多媒体文件,得到的id
|
|
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static function voice($tousername, $mediaId){
|
|
|
|
public static function voice($tousername, $mediaId){
|
|
|
|
//获取ACCESS_TOKEN
|
|
|
|
//获取ACCESS_TOKEN
|
|
|
|
$accessToken = AccessToken::getAccessToken();
|
|
|
|
$accessToken = AccessToken::getAccessToken();
|
|
|
@ -57,6 +85,14 @@ class ResponseInitiative{
|
|
|
|
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
|
|
|
|
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @descrpition 视频
|
|
|
|
|
|
|
|
* @param $tousername
|
|
|
|
|
|
|
|
* @param $mediaId 通过上传多媒体文件,得到的id
|
|
|
|
|
|
|
|
* @param $title 标题
|
|
|
|
|
|
|
|
* @param $description 描述
|
|
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static function video($tousername, $mediaId, $title, $description){
|
|
|
|
public static function video($tousername, $mediaId, $title, $description){
|
|
|
|
//获取ACCESS_TOKEN
|
|
|
|
//获取ACCESS_TOKEN
|
|
|
|
$accessToken = AccessToken::getAccessToken();
|
|
|
|
$accessToken = AccessToken::getAccessToken();
|
|
|
@ -76,7 +112,16 @@ class ResponseInitiative{
|
|
|
|
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
|
|
|
|
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @descrpition 音乐
|
|
|
|
|
|
|
|
* @param $tousername
|
|
|
|
|
|
|
|
* @param $title 标题
|
|
|
|
|
|
|
|
* @param $description 描述
|
|
|
|
|
|
|
|
* @param $musicUrl 音乐链接
|
|
|
|
|
|
|
|
* @param $hqMusicUrl 高质量音乐链接,WIFI环境优先使用该链接播放音乐
|
|
|
|
|
|
|
|
* @param $thumbMediaId 缩略图的媒体id,通过上传多媒体文件,得到的id
|
|
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static function music($tousername, $title, $description, $musicUrl, $hqMusicUrl, $thumbMediaId){
|
|
|
|
public static function music($tousername, $title, $description, $musicUrl, $hqMusicUrl, $thumbMediaId){
|
|
|
|
//获取ACCESS_TOKEN
|
|
|
|
//获取ACCESS_TOKEN
|
|
|
|
$accessToken = AccessToken::getAccessToken();
|
|
|
|
$accessToken = AccessToken::getAccessToken();
|
|
|
@ -98,6 +143,15 @@ class ResponseInitiative{
|
|
|
|
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
|
|
|
|
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @descrpition 图文消息 - 单个项目的准备工作,用于内嵌到self::news()中。现调用本方法,再调用self::news()
|
|
|
|
|
|
|
|
* 多条图文消息信息,默认第一个item为大图,注意,如果调用本方法得到的数组总项数超过10,则将会无响应
|
|
|
|
|
|
|
|
* @param $title 标题
|
|
|
|
|
|
|
|
* @param $description 描述
|
|
|
|
|
|
|
|
* @param $picUrl 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
|
|
|
|
|
|
|
|
* @param $url 点击图文消息跳转链接
|
|
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static function newsItem($title, $description, $picUrl, $url){
|
|
|
|
public static function newsItem($title, $description, $picUrl, $url){
|
|
|
|
return $template = array(
|
|
|
|
return $template = array(
|
|
|
|
'title'=>$title,
|
|
|
|
'title'=>$title,
|
|
|
@ -107,12 +161,18 @@ class ResponseInitiative{
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @descrpition 图文 - 先调用self::newsItem()再调用本方法
|
|
|
|
|
|
|
|
* @param $tousername
|
|
|
|
|
|
|
|
* @param $item 数组,每个项由self::newsItem()返回
|
|
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static function news($tousername, $item){
|
|
|
|
public static function news($tousername, $item){
|
|
|
|
|
|
|
|
//获取ACCESS_TOKEN
|
|
|
|
$accessToken = AccessToken::getAccessToken();
|
|
|
|
$accessToken = AccessToken::getAccessToken();
|
|
|
|
self::$queryUrl = self::$queryUrl.$accessToken;
|
|
|
|
self::$queryUrl = self::$queryUrl.$accessToken;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//开始
|
|
|
|
$template = array(
|
|
|
|
$template = array(
|
|
|
|
'touser'=>$tousername,
|
|
|
|
'touser'=>$tousername,
|
|
|
|
'msgtype'=>'news',
|
|
|
|
'msgtype'=>'news',
|
|
|
|