|
本帖最后由 Closer 于 2015-3-20 09:34 编辑
为什么我用CI 开发的微信公众平台消息回复功能,有时候好用,有时候就直接弹出该公众号暂时无法提供消息呢!PHP复制代码
<?php
$post_obj = simplexml_load_string($post_str, 'SimpleXMLElement', LIBXML_NOCDATA );
$from_username = $post_obj->FromUserName;
$to_username = $post_obj->ToUserName;
// $keyword 就是用户输入的内容
$keyword = trim($post_obj->Content);
$type = $post_obj->MsgType;
$content = $this->_parseMessage ($keyword);
$data_subscribe = array(
'to' => $from_username,
'from' => $to_username,
);
if($type=='event'){
if($post_obj->Event=='subscribe'){
$sr='sub';
$this->db->where('sub_re',$sr);
$this->db->order_by('id','desc');
$res=$this->db->get('tb_content',1);
$cres=$res->row_array();
$sub_re=$cres['type'];
$title=$cres['title'];
$content=$cres['contents'];
if($sub_re=='news'){
$picurl=$cres['picurl'];
$url=$cres['url'];
$desc=$cres['desc'];
// $this->load->view('response_view_subscribe',$data_subscribe);
$textTpl=
"<xml>
<ToUserName>$from_username</ToUserName>
<FromUserName>$to_username</FromUserName>
<CreateTime><?=time()?></CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<Content>$content</Content>
<ArticleCount>1</ArticleCount>
<Articles>
<item>
<Title>$title</Title>
<Description>$desc</Description>
<PicUrl>$picurl</PicUrl>
<Url>$url</Url>
</item>
</Articles>
</xml>";
echo $textTpl;
}elseif($sub_re=='text'){
$textTpl=
"<xml>
<ToUserName>$from_username</ToUserName>
<FromUserName>$to_username</FromUserName>
<CreateTime><?=time()?></CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content>$content</Content>
</xml>";
echo $textTpl;
}else{
echo '';
}
}else{
echo '';
}
}elseif($type=='text'){
$sr='re';
$this->db->where('sub_re',$sr);
$this->db->order_by('id','desc');
$res=$this->db->get('tb_content',1);
$cres=$res->row_array();
$sub_re=$cres['type'];
$title=$cres['title'];
$content=$cres['contents'];
if($sub_re=='news'){
$type='text';
$picurl=$cres['picurl'];
$url=$cres['url'];
$desc=$cres['desc'];
// $this->load->view('response_view_subscribe',$data_subscribe);
$textTpl=
"<xml>
<ToUserName>$from_username</ToUserName>
<FromUserName>$to_username</FromUserName>
<CreateTime><?=time()?></CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<Content>$content</Content>
<ArticleCount>1</ArticleCount>
<Articles>
<item>
<Title>$title</Title>
<Description>$desc</Description>
<PicUrl>$picurl</PicUrl>
<Url>$url</Url>
</item>
</Articles>
</xml>";
echo $textTpl;
}elseif($sub_re=='text'){
$type='text';
$textTpl=
"<xml>
<ToUserName>$from_username</ToUserName>
<FromUserName>$to_username</FromUserName>
<CreateTime><?=time()?></CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content>$content</Content>
<FuncFlag>0</FuncFlag>
</xml>";
echo $textTpl;
}else{
echo '';
}
}else{
echo '';
exit;
}
}
复制代码
这是数据处理的代码!!求大神指导!!!
|
|