bin.shen
2016-12-05 a4c9331bbfe3e8765ccdc1c54cc6931bac49cc82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
//文本回复
function _response_text($object,$content){
    $textTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <FromUserName><![CDATA[%s]]></FromUserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[%s]]></MsgType>
                <Content><![CDATA[%s]]></Content>
                <FuncFlag>%d</FuncFlag>
                </xml>";
    $FuncFlag = 0;
    $resultStr = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), "text", $content,$FuncFlag);
    return $resultStr;
}
//单图文
function  _response_news($object,$newsContent){
    $newsTplHead = "<xml>
                    <ToUserName><![CDATA[%s]]></ToUserName>
                    <FromUserName><![CDATA[%s]]></FromUserName>
                    <CreateTime>%s</CreateTime>
                    <MsgType><![CDATA[news]]></MsgType>
                    <ArticleCount>1</ArticleCount>
                    <Articles>";
    $newsTplBody = "<item>
                    <Title><![CDATA[%s]]></Title> 
                    <Description><![CDATA[%s]]></Description>
                    <PicUrl><![CDATA[%s]]></PicUrl>
                    <Url><![CDATA[%s]]></Url>
                    </item>";
    $newsTplFoot = "</Articles>
                    <FuncFlag>[%s]</FuncFlag>
                    </xml>";
    $header = sprintf($newsTplHead, $object->FromUserName, $object->ToUserName, time());
    
    
    $title = $newsContent['title'];
    $desc = $newsContent['description'];
    $picUrl = $newsContent['picUrl'];
    $url = $newsContent['url'];
    $body = sprintf($newsTplBody, $title, $desc, $picUrl, $url);
    
    $FuncFlag = 0;
    $footer = sprintf($newsTplFoot, $FuncFlag);
    
    return $header.$body.$footer;
}
 
//多图文
function _response_multiNews($object,$newsContent)
{
    $newsTplHead = "<xml>
                    <ToUserName><![CDATA[%s]]></ToUserName>
                    <FromUserName><![CDATA[%s]]></FromUserName>
                    <CreateTime>%s</CreateTime>
                    <MsgType><![CDATA[news]]></MsgType>
                    <ArticleCount>%s</ArticleCount>
                    <Articles>";
    $newsTplBody = "<item>
                    <Title><![CDATA[%s]]></Title> 
                    <Description><![CDATA[%s]]></Description>
                    <PicUrl><![CDATA[%s]]></PicUrl>
                    <Url><![CDATA[%s]]></Url>
                    </item>";
    $newsTplFoot = "</Articles>
                    <FuncFlag>0</FuncFlag>
                    </xml>";
 
    $bodyCount = count($newsContent);
    $bodyCount = $bodyCount < 10 ? $bodyCount : 10;
 
    $header = sprintf($newsTplHead, $object->FromUserName, $object->ToUserName, time(), $bodyCount);
    
    foreach($newsContent as $key => $value){
        $body .= sprintf($newsTplBody, $value['title'], $value['description'], $value['picUrl'], $value['url']);
    }
 
    $FuncFlag = 0;
    $footer = sprintf($newsTplFoot, $FuncFlag);
 
    return $header.$body.$footer;
}
 
?>