PHP code example of techotaku / wechat-sdk
1. Go to this page and download the library: Download techotaku/wechat-sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
techotaku / wechat-sdk example snippets
define('TOKEN', ''); // 微信通信令牌,在公众平台管理后台设置
define('DEBUG', TRUE); // 调试模式开关,指示是否将错误信息通过文本消息回复(如果可能)。
$wechat = new \Wechat(TOKEN, DEBUG);
/**
* 微信公众平台传入消息类
* 包含传入消息类型常量定义
*/
class WechatRequest {
const text = 'text';
const image = 'image';
const location = 'location';
const link = 'link';
const subscribe = 'subscribe';
const voice = 'voice';
const unsubscribe = 'unsubscribe';
const unknown = 'unknown';
}
/**
* 回复消息
*
* @param string $type 消息类型,在类WechatResponse中定义
* @param string $params 消息参数,与消息类型相关:
* WechatResponse::text 文本消息 $params为消息内容
* $params 消息文本
* WechatResponse::news 图文消息 $params为数组
* $params 由单条图文消息类型 WechatNewsResponseItem 组成的数组
* WechatResponse::music 音乐消息 $params为关联数组
* $params['title']
* $params['description']
* $params['musicUrl']
* $params['hqMusicUrl']
* @return void
*/
public function sendResponse($type, $params)
$array = array(
new WechatNewsResponseItem('图文消息标题', '图文消息说明', '图片地址', '点击转向的链接'),
new WechatNewsResponseItem('图文消息标题', '图文消息说明', '图片地址', '点击转向的链接')
);