根据微信的文档开发了,一直不能成功
文档 :https://mp.weixin.qq.com/wiki...
public function responseImage($postObj){
$xmltpl = "<xml>
<ToUserName>< ![CDATA[%s] ]></ToUserName>
<FromUserName>< ![CDATA[%s] ]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType>< ![CDATA[image] ]></MsgType>
<Image>
<MediaId>< ![CDATA[%s] ]></MediaId>
</Image>
</xml>";
$result = sprintf($xmltpl, $postObj->FromUserName, $postObj->ToUserName,time(),$postObj->MediaId);
return $result;
}
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
发送图片后报错:该公众号服务出现故障
已下文本消息回复 是正确的,单图就不行了,用的是加密模式。
大侠们,帮忙看看 ,有什么错误的地方么,怎么解决啊?
谢了
public function responseText($postObj){
//定义返回的文本信息
$content = $postObj -> Content;
$xmltpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>";
$result = sprintf($xmltpl, $postObj->FromUserName, $postObj->ToUserName, time(), $content);
return $result;
}
加密代码
//加密
if ($encrypt_type == 'aes'){
$encryptMsg = ''; //加密后的密文
$errCode = $pc->encryptMsg($result, $timeStamp, $nonce, $encryptMsg);
$result = $encryptMsg;
}
echo $result;
这是一个坑
xml模板不能有空格,清除掉就可以了
微信官方文档给的模板有空,但没有做提示。