当前位置: 首页 > 后端技术 > PHP

微信公众号开发:自动回复文字-图片-图文-关键词回复-上传素材-自定义菜单

时间:2023-03-29 16:23:26 PHP

对接流程1.申请微信公众号测试账号URL:https://mp.weixin.qq.com/debu...2.登录,配置开发者服务器URL和Token开发者服务器配置代码:config.phpvalid();classwechat{publicfunctionvalid(){$echoStr=$_GET["echostr"];if($this->checkSignature()){echo$echoStr;出口;}}私有函数checkSignature(){$signature=$_GET["signature"];$timestamp=$_GET["时间戳"];$nonce=$_GET["nonce"];$令牌=令牌;$tmpArr=array($token,$timestamp,$nonce);排序($tmpArr);$tmpStr=内爆($tmpArr);$tmpStr=sha1($tmpStr);如果($tmpStr==$signature){返回真;}else{返回错误;}}}?>URL为config.php你服务器的URLToken为上面代码设置的Token后,就可以完成接口配置绑定了。开发清除config.php的代码,粘贴下面的代码,保存。FromUserName;//$toUsername=$postObj->ToUserName;//内容$content=trim($postObj->Content);//消息类型$msgType=$postObj->MsgType;//时间戳$time=time();//短信XML模板$textTpl="%s";//图像消息XML模板$imageTpl="%s";//图片材质ID$media_id="GHYb4PhayrbCAWgHCwkBQIAg_b46UI0Dl-xJukV-XoryFMp-t5c50_VqyId074_U";//短信XML模板$newsTpl="%s1<文章><项目><标题><描述>";//根据关键字还原if($content=='Hello'){//发送向用户发送短信echosprintf($textTpl,$fromUsername,$toUsername,$time,"text",$content);}elseif($content=='picture'){//向用户发送图片消息echosprintf($imageTpl,$fromUsername,$toUsername,$time,"image",$media_id);}elseif($content=='text'){//发送短信给用户echosprintf($newsTpl,$fromUsername,$toUsername,$time,"news","这是图文信息","给中国发个信息就可以生成卡片了!","https://d1.faiusr.com/2/AAEIABACGAAg_vuznQYogr-b2gIwuAg4uAg.jpg","https://www.qq.com");}?>经验希望对你有所帮助。微信:sansure2016网址:likeyunba.com日期:2019-12-20作者:Tanking