代码拉取完成,页面将自动刷新
同步操作将从 youwen21/exwechat 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?php
namespace youwen\exwechat;
class exXMLMaker
{
private $_FromUserName = '';
private $_ToUserName = '';
public function __construct($FromUserName = '', $ToUserName='')
{
if(empty($FromUserName) || empty($ToUserName)){
$msg = exRequest::instance()->getMsg();
$this->_FromUserName = $msg['FromUserName'];
$this->_ToUserName = $msg['ToUserName'];
}else{
$this->_FromUserName = $FromUserName;
$this->_ToUserName = $ToUserName;
}
}
//创建文本消息
private $textTpl = '<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>0</FuncFlag>
</xml>';
public function createText($contentStr='', $from='', $to='')
{
$FromUserName = empty($from)? $this->_FromUserName : $from;
$ToUserName = empty($to)? $this->_ToUserName : $to;
empty($contentStr) ? $contentStr = "谢谢关注" : $contentStr;
return sprintf($this->textTpl, $FromUserName, $ToUserName, time(), 'text', $contentStr);
}
public function createNews($newres=[], $from='', $to='')
{
$FromUserName = empty($from)? $this->_FromUserName : $from;
$ToUserName = empty($to)? $this->_ToUserName : $to;
$str = "<xml>";
$str .= "<ToUserName><![CDATA[" . $FromUserName . "]]></ToUserName>";
$str .= "<FromUserName><![CDATA[" . $ToUserName . "]]></FromUserName>";
$str .= "<CreateTime>" . time() . "</CreateTime>";
$str .= "<MsgType><![CDATA[news]]></MsgType>";
$str .= "<ArticleCount>" . count($newres) . "</ArticleCount>";
$str .= "<Articles>";
foreach ($newres as $value) {
// url关键字替换成用户openid
$url = str_replace('openidvalue', $FromUserName, $value['url']);
$str .= "<item>";
$str .= "<Title><![CDATA[" . $value['title'] . "]]></Title>";
$str .= "<Description><![CDATA[" . $value['description'] . "]]></Description>";
$str .= "<PicUrl><![CDATA[" . $value['picurl'] . "]]></PicUrl>";
$str .= "<Url><![CDATA[" . $url . "]]></Url>";
$str .= "</item>";
}
$str .= "</Articles>";
$str .= "</xml>";
return $str;
}
protected function response_image($media_id = '', $from='', $to='')
{
$FromUserName = empty($from)? $this->_FromUserName : $from;
$ToUserName = empty($to)? $this->_ToUserName : $to;
$str = '<xml>';
$str .= '<ToUserName><![CDATA[' . $FromUserName . ']]></ToUserName>';
$str .= '<FromUserName><![CDATA[' . $ToUserName . ']]></FromUserName>';
$str .= '<CreateTime>' . time() . '</CreateTime>';
$str .= '<MsgType><![CDATA[image]]></MsgType>';
$str .= '<Image>';
$str .= '<MediaId><![CDATA[' . $media_id . ']]></MediaId>';
$str .= '</Image>';
$str .= '</xml>';
return $str;
}
public static function arrToXml(array $data, $cdata=[])
{
$cdataKey = array_merge(['detail', 'scene_info'], $cdata);
$xml = '<xml>';
foreach ($data as $key => $value) {
if(in_array($key, $cdataKey)){
$xml .='<'.$key.'><![CDATA['.$value.']]></'.$key.'>';
}else{
$xml .='<'.$key.'>'.$value.'</'.$key.'>';
}
}
$xml .='</xml>';
return $xml;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。