You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
git-test/core/responseinitiative.lib.php

188 lines
5.9 KiB

2 months ago
<?php
namespace LaneWeChat\Core;
/**
* 发送主动响应
* Created by Lane.
* User: lane
* Date: 13-12-29
* Time: 下午5:54
* Mail: lixuan868686@163.com
* Website: http://www.lanecn.com
*/
2 months ago
class ResponseInitiative{
protected static $queryUrl = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=';
protected static $action = 'POST';
/**
* @descrpition 文本
* @param $tousername
* @param $content 回复的消息内容换行在content中能够换行微信客户端就支持换行显示
* @return string
*/
public static function text($tousername, $content){
//获取ACCESS_TOKEN
2 months ago
$accessToken = AccessToken::getAccessToken();
self::$queryUrl = self::$queryUrl.$accessToken;
//开始
2 months ago
$template = array(
'touser'=>$tousername,
'msgtype'=>'text',
'text'=>array(
'content'=>$content,
),
);
$template = json_encode($template);
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
}
/**
* @descrpition 图片
* @param $tousername
* @param $mediaId 通过上传多媒体文件得到的id。
* @return string
*/
2 months ago
public static function image($tousername, $mediaId){
//获取ACCESS_TOKEN
$accessToken = AccessToken::getAccessToken();
self::$queryUrl = self::$queryUrl.$accessToken;
//开始
$template = array(
'touser'=>$tousername,
'msgtype'=>'image',
'image'=>array(
'media_id'=>$mediaId,
),
);
$template = json_encode($template);
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
}
/**
* @descrpition 语音
* @param $tousername
* @param $mediaId 通过上传多媒体文件得到的id
* @return string
*/
2 months ago
public static function voice($tousername, $mediaId){
//获取ACCESS_TOKEN
$accessToken = AccessToken::getAccessToken();
self::$queryUrl = self::$queryUrl.$accessToken;
//开始
$template = array(
'touser'=>$tousername,
'msgtype'=>'voice',
'voice'=>array(
'media_id'=>$mediaId,
),
);
$template = json_encode($template);
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
}
/**
* @descrpition 视频
* @param $tousername
* @param $mediaId 通过上传多媒体文件得到的id
* @param $title 标题
* @param $description 描述
* @return string
*/
2 months ago
public static function video($tousername, $mediaId, $title, $description){
//获取ACCESS_TOKEN
$accessToken = AccessToken::getAccessToken();
self::$queryUrl = self::$queryUrl.$accessToken;
//开始
$template = array(
'touser'=>$tousername,
'msgtype'=>'video',
'video'=>array(
'media_id'=>$mediaId,
'title'=>$title,
'description'=>$description,
),
);
$template = json_encode($template);
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
*/
2 months ago
public static function music($tousername, $title, $description, $musicUrl, $hqMusicUrl, $thumbMediaId){
//获取ACCESS_TOKEN
$accessToken = AccessToken::getAccessToken();
self::$queryUrl = self::$queryUrl.$accessToken;
//开始
$template = array(
'touser'=>$tousername,
'msgtype'=>'music',
'music'=>array(
'title'=>$title,
'description'=>$description,
'musicurl'=>$musicUrl,
'hqmusicurl'=>$hqMusicUrl,
'thumb_media_id'=>$thumbMediaId,
),
);
$template = json_encode($template);
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
*/
2 months ago
public static function newsItem($title, $description, $picUrl, $url){
return $template = array(
'title'=>$title,
'description'=>$description,
'url'=>$picUrl,
'picurl'=>$url,
);
}
/**
* @descrpition 图文 - 先调用self::newsItem()再调用本方法
* @param $tousername
* @param $item 数组每个项由self::newsItem()返回
* @return string
*/
2 months ago
public static function news($tousername, $item){
//获取ACCESS_TOKEN
2 months ago
$accessToken = AccessToken::getAccessToken();
self::$queryUrl = self::$queryUrl.$accessToken;
//开始
2 months ago
$template = array(
'touser'=>$tousername,
'msgtype'=>'news',
'news'=>array(
'articles'=>$item
),
);
$template = json_encode($template);
return Curl::callWebServer(self::$queryUrl, $template, self::$action);
}
}