dubin521 发表于 2015-3-19 19:38:39

微信公众平台开发

本帖最后由 Closer 于 2015-3-20 09:34 编辑

为什么我用CI 开发的微信公众平台消息回复功能,有时候好用,有时候就直接弹出该公众号暂时无法提供消息呢!
<?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><!]></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><!]></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><!]></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><!]></MsgType>
      <Content>$content</Content>
      <FuncFlag>0</FuncFlag>
      </xml>";
    echo $textTpl;
}else{
    echo '';
}
}else{
echo '';
exit;
}
}


这是数据处理的代码!!求大神指导!!!
Closer : 已排版

yuzhigang5460 发表于 2015-3-20 16:17:17

1、开发者在5秒内未回复任何内容
2、开发者回复了异常数据,比如JSON数据等

因此可以判断: 1. 网速太慢, 2. 发生了异常。

dubin521 发表于 2015-3-23 11:01:57

yuzhigang5460 发表于 2015-3-20 16:17
1、开发者在5秒内未回复任何内容
2、开发者回复了异常数据,比如JSON数据等



已经解决了,忘记了 验证一次就不要在验证了
页: [1]
查看完整版本: 微信公众平台开发