return和echo有什么区别

浏览:2052 发布日期:2017/03/14 分类:ThinkPHP5专区
function cwxsm($uid,$cid,$mchno,$paytype,$money,$orderno,$notifyurl,$returnurl,$attach)
{
$pid=2; //通道ID
$out=json_encode(array('result'=>10,'message'=>'异常错误'));
$ct['uid']=$uid;
$ct['pid']=$pid;
$ct['cid']=$cid;
$ct['paymentno']=md5(time() . mt_rand(1000,9999));
$ct['orderno']=$orderno;
$ct['payfee']=$money;
$ct['stime']=date('Y-m-d H:i:s');
$ct['paytype']=$paytype;
$ct['returnurl']=$returnurl;
$ct['notifyurl']=$notifyurl;
$ct['attach']=$attach;
$ct['sign']=md5($orderno . $mchno . $this->mkey);
$result=$this->Data->indata($ct);
if($pid==2){
$mchno='1858';
$key='key';
$sign=md5($mchno.'|'. $money .'|'. $key);
$notifyUrl=App_URL . '/Api/huitiao/zjwxsm';
$result="http://url/api/?mchno={$mchno}&money={$money}&orderno={$ct['paymentno']}&payType={$paytype}¬ifyUrl={$notifyUrl}&returnUrl={$returnurl}&attach={$attach}&sign={$sign}";
$headers = get_headers($result, TRUE);
$ewm=$headers['location'];
if(stripos($ewm,'?data=')!==false){
$json['result']="1";
$json['message']=App_URL . "/qrcode.php?data=".explode('?data=',$ewm)[1];
}else{
$json['result']="11";
$json['message']="通道关闭";
}
$out=json_encode($json);
}
return $out; //这里如果用echo就没有问题,但如果用return 程序就会被执行两次,为什么呢?
}
最佳答案
评论( 相关
后面还有条评论,点击查看>>