wechattemplate.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Created by 上海风车教育科技有限公司.
  4. * User: 刘红伟
  5. * Date: 15-11-26
  6. * Email: 454303753@qq.com
  7. * File:wechattemplate.php
  8. */
  9. class wechattemplate{
  10. const MSG_TYPE = 1;
  11. private $tpl;
  12. public function __construct($type=self::MSG_TYPE){
  13. switch($type){
  14. case 'test':
  15. $this->_text();
  16. break;
  17. case 'image':
  18. $this->_image();
  19. break;
  20. case 'voice':
  21. $this->_voice();
  22. break;
  23. case 'video':
  24. $this->_video();
  25. break;
  26. case 'music':
  27. $this->_music();
  28. break;
  29. case 'news':
  30. $this->_news();
  31. break;
  32. default:
  33. $this->_text();
  34. }
  35. }
  36. private function _text(){
  37. $this->tpl="<xml>
  38. <ToUserName><![CDATA[%s]]></ToUserName>
  39. <FromUserName><![CDATA[%s]]></FromUserName>
  40. <CreateTime>%s</CreateTime>
  41. <MsgType><![CDATA[text]]></MsgType>
  42. <Content><![CDATA[%s]]></Content>
  43. </xml>";
  44. }
  45. private function _image(){
  46. $this->tpl="<xml>
  47. <ToUserName><![CDATA[%s]]></ToUserName>
  48. <FromUserName><![CDATA[%s]]></FromUserName>
  49. <CreateTime>%s</CreateTime>
  50. <MsgType><![CDATA[image]]></MsgType>
  51. <Image>
  52. <MediaId><![CDATA[%s]]></MediaId>
  53. </Image>
  54. </xml>";
  55. }
  56. private function _voice(){
  57. $this->tpl="
  58. <xml>
  59. <ToUserName><![CDATA[%s]]></ToUserName>
  60. <FromUserName><![CDATA[%s]]></FromUserName>
  61. <CreateTime>%s</CreateTime>
  62. <MsgType><![CDATA[voice]]></MsgType>
  63. <Voice>
  64. <MediaId><![CDATA[%s]]></MediaId>
  65. </Voice>
  66. </xml>
  67. ";
  68. }
  69. private function _video(){
  70. $this->tpl="
  71. <xml>
  72. <ToUserName><![CDATA[%s]]></ToUserName>
  73. <FromUserName><![CDATA[%s]]></FromUserName>
  74. <CreateTime>%s</CreateTime>
  75. <MsgType><![CDATA[video]]></MsgType>
  76. <Video>
  77. <MediaId><![CDATA[%s]]></MediaId>
  78. <Title><![CDATA[%s]]></Title>
  79. <Description><![CDATA[%s]]></Description>
  80. </Video>
  81. </xml>
  82. ";
  83. }
  84. private function _music(){
  85. $this->tpl="
  86. <xml>
  87. <ToUserName><![CDATA[%s]]></ToUserName>
  88. <FromUserName><![CDATA[%s]]></FromUserName>
  89. <CreateTime>%s</CreateTime>
  90. <MsgType><![CDATA[music]]></MsgType>
  91. <Music>
  92. <Title><![CDATA[%s]]></Title>
  93. <Description><![CDATA[%s]]></Description>
  94. <MusicUrl><![CDATA[%s]]></MusicUrl>
  95. <HQMusicUrl><![CDATA[%s]]></HQMusicUrl>
  96. <ThumbMediaId><![CDATA[%s]]></ThumbMediaId>
  97. </Music>
  98. </xml>
  99. ";
  100. }
  101. private function _news(){
  102. $this->tpl="
  103. <xml>
  104. <ToUserName><![CDATA[%s]]></ToUserName>
  105. <FromUserName><![CDATA[%s]]></FromUserName>
  106. <CreateTime>%s</CreateTime>
  107. <MsgType><![CDATA[news]]></MsgType>
  108. <ArticleCount>1</ArticleCount>
  109. <Articles>
  110. <item>
  111. <Title><![CDATA[%s]]></Title>
  112. <Description><![CDATA[%s]]></Description>
  113. <PicUrl><![CDATA[%s]]></PicUrl>
  114. <Url><![CDATA[%s]]></Url>
  115. </item>
  116. </Articles>
  117. </xml>
  118. ";
  119. }
  120. public function getTpl(){
  121. return $this->tpl;
  122. }
  123. }