基于zhphpWeixinApi.class.php 接口类使用示例

helloword开始 做第一个案例,文本发送,简单的机器人
<?php
header('Content-type: text/html; charset=utf-8');#设置头信息
require_once('zhphpWeixinApi.class.php');#加载微信接口类文件
$zhwx=new zhphpWeixinApi();//实例化
$configArr=array(
				'token'=>'wxtest1',
				'appid'=>'wx5b79a26868798826',
				'appSecret'=>'a95952819cc768fc130bc0cc0444ae77',
				'myweixinId'=>'gh_746ed5c6a58b'
				);
$zhwx->setConfig($configArr);//配置文件
if($zhwx->validToken()){
	if($zhwx->weixinBaseApiMessage()){
		$keyword=$zhwx->getUserTextRequest();//得到用户发的微信内容
		$msgtype=$zhwx->getUserMsgType();//得到用户发的微信数据类型
		$SendTime=$zhwx->getUserSendTime();//得到用户发送的时间
		if($msgtype == 'text'){
			$content='';
			switch($keyword){
				case '你好':$content='hello'; break;
                case '成都':$content='成都号称"天府之国",坐落于成都平原,是西南重镇';break;
                case  'zh':$content='zhphp';break;
                default: $content='感谢你关注zhphp微信平台';break;			
			}
			$zhwx->responseMessage('text',$content);
		}
	}
}

发布了186 篇原创文章 · 获赞 24 · 访问量 31万+

猜你喜欢

转载自blog.csdn.net/echocdzh/article/details/52640564
今日推荐