<?php
check("shentong","368373723473","moult","13800000000","商品名称");
function check($gongsi,$haoma,$name,$telno,$goods)
{
//通过xml获取最后一条快递信息
$apione=file_get_contents('http://api.kuaidi100.com/apione?com='.$gongsi.'&nu='.$haoma.'&show=1');
$dom = new DOMDocument('1.0');
$dom ->loadXML($apione);
$xml = simplexml_import_dom($dom);
$kdtime = $xml ->data[0]->time;
$context = $xml ->data[0]->context;
$kdtime=trim(substr($kdtime,10));//取消时间的年,删除前后空格
$context=str_replace(" ","",$context);//删除全部空格$file='data/'.$haoma.'.txt';
if(!file_exists($file)){ $handle=fopen($file,"w"); };//创建txt数据库
$bendi=file_get_contents($file);//获取本地数据if($context != ''){
$msg="亲爱的".$name.",您购买的“".$goods."”的物流信息于".$kdtime."变更为“".$context."”。【moult】";//生成提醒短信文字if($bendi != $msg){//如果新的信息与本地不同$msgurl="http://165266cn.host3.idcnow.com/smswin.jsp?&tel=".$telno."&username=cs&pwd=000000&content=".urlencode($msg);//短信发送的URL接口
$callback=fopen($msgurl,"r");//发送短信并取回信息if( $callback = '0'){//如果短信发送成功就写入本地数据
$fp2=fopen($file,"w");
fwrite($fp2,$msg);
fclose($fp2);
};
};};
};
?>
情况是这样的,当这个代码执行时,什么功能都正常,就是不能提交到短信发送接口,短信接口返回的数据说提交的短信内容为空。
但是如果把发送这个模块单独拿出来执行(同样的请求网址和代码),又可以成功发送短信的。只要放在这个文件里面面就不能正常提交。
用fopen和file_get_contents这两个函数都不能。
(为了防止被恶意使用,代码中短信接口的密码和用户名是错了的。)
应该在函数的末尾加一句
return $callback ;
然后在文件中使用时
echo $out = check(....) == '0' ? '发送成功':'发送失败';
我怀疑是不是字数限制?