PHP给微信平台发送xml的问题 微信phpxml开发模式 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可能是封装好的,你看下$resultStr 这个到底哪里调用了。应该能找到结果。 xml封装在$textTpl private function transmitText($object, $content, $flag = 0){ $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[%s]]></Content> <FuncFlag>%d</FuncFlag> </xml>"; $resultStr = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content, $flag); return $resultStr; } 你只需要生成好微信规定的xml格式内容,微信服务端自然会返回结果。 附上代码供参考function xmlCurlPost($xmlData, $url, $timeoutMs=30000){ $ch = curl_init(); $header[] = "Content-type: text/xml";//定义content-type为xml curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData); curl_setopt($ch, CURLOPT_NOSIGNAL, 1); //注意,毫秒超时一定要设置这个 curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeoutMs); //超时毫秒,cURL 7.16.2中被加入。从PHP 5.2.3起可使用 $sContent = curl_exec($ch); $aStatus = curl_getinfo($ch); curl_close($ch); if(intval($aStatus["http_code"])==200){ return trim($sContent); }else{ return false; }}$postStr = file_get_contents("php://input");$return = xmlCurlPost($postStr, $url, $timeoutMs); 正规表达式匹配的问题 求一个正则.. Zend汉化求助. php可不可以通过GD库把一个网页输出为图片呢? php中如何显示函数本身的内容 懂PHP和MYSQL的请进 ---------请教统计数量 为什么我做的新闻发布系统显示时候,在某些IE版本中全角空格显示为“?” 请教 smarty在页面上输出源代码 托管的php网站上传图片有限制 asp那边都没人在活动吗 希望这懂asp的帮我看下问题 根据人数随机分配百分比的问题
private function transmitText($object, $content, $flag = 0){
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>%d</FuncFlag>
</xml>";
$resultStr = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content, $flag);
return $resultStr;
}
{
$ch = curl_init();
$header[] = "Content-type: text/xml";//定义content-type为xml
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1); //注意,毫秒超时一定要设置这个
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeoutMs); //超时毫秒,cURL 7.16.2中被加入。从PHP 5.2.3起可使用
$sContent = curl_exec($ch);
$aStatus = curl_getinfo($ch);
curl_close($ch);
if(intval($aStatus["http_code"])==200){
return trim($sContent);
}else{
return false;
}
}$postStr = file_get_contents("php://input");
$return = xmlCurlPost($postStr, $url, $timeoutMs);