支付宝回调地址判断的问题

来求解的 发布于 2014/11/26 14:15
阅读 1K+
收藏 0
<?php
include('common.php');
switch($act){
case 'getpost':
if ($_p_code!=$_SESSION['code'] or $_p_code==NULL)pe_error('非法访问','','dailog');unset($_SESSION['code']);
//提交订单前的准备活动
//选择推荐人信息,
if ($_COOKIE['domain_sub']) {
$user_tj = $db->pe_select('user', array('user_name'=>$_COOKIE['domain_sub']));
$_p_order['user_name_tj']=$_COOKIE['domain_sub'];
if($user_tj['user_name']){
$add_user['user_id_tj'] = $user_tj['user_id'];
$add_user['user_name_tj'] = $user_tj['user_name'];
}
}
if(!$_s_user_id){
//通过电子邮件检查用户是否存在
$user_info = $db->pe_select('user', array('user_email'=>$_p_order['user_email']),'user_id');
$user_id=$user_info['user_id'];
if(empty($user_id)){
//注册用户为购买用户
$r=mysql_query('show table status where name ="cps_user"', $db->dbconn);
$id = mysql_result($r, 0, 'Auto_increment');
$add_user['user_name']='ms'.$id;
$r = $db->pe_select('user', array('user_name'=>$add_user['user_name']),'user_id');
if($r)$add_user['user_name']=$add_user['user_subdomain']='ms'.$id.random(6);
$def_pw='123456';//默认密码
$add_user['user_tname']= $_p_order['user_tname'];
$add_user['user_pw'] = md5($def_pw);
$add_user['user_email'] = $_p_order['user_email'];
$add_user['user_phone'] = $_p_order['user_phone'];
$add_user['user_atime'] = TIME;
$add_user['user_level']=2;
//手机号码不能重复
$r = $db->pe_select('user', array('user_phone'=>$_p_order['user_phone']));
if($r){
$add_user['user_phone'] = '';
}
$user_id = $db->pe_insert('user', $add_user);
$db->pe_insert('user_data',array('user_id'=>$user_id,'address'=>$_p_order['user_address']));
$_SESSION['user_id'] = $user_id;
$_SESSION['user_name'] = $add_user['user_name'];
$_SESSION['user_level'] = 2;
//发邮件
$st='reg';
$add_user['site_name']=$cache_setting['web_title']['setting_value'];
pe_lead('hook/order.hook.php');
$email['qunfa_name'] = orderemail($st,'name',$add_user);
$email['qunfa_text'] = orderemail($st,'text',$add_user);

$user['user_name'] = $add_user['user_tname'];
$user['user_email'] = $add_user['user_email'];
pe_lead('hook/qunfa.hook.php');
$r=qunfa_emailone($email, $user);
}
}
$name_money = explode('|',$_p_name_money);
$_p_order['order_name']=$name_money[0];
$_p_order['order_money']=$name_money[1];
$_p_order['order_state']='notpay';
$_p_order['user_id']=$user_id?$user_id:$_SESSION['user_id'];
$_p_order['order_atime']=TIME;
if(empty($_p_order['package_id']) or empty($_p_order['order_money']) or empty($_p_order['user_id']))pe_error('下单数据丢失!');

$order_id = $db->pe_insert('order', pe_dbhold($_p_order));
if(empty($order_id))pe_error('下单失败!');
pe_lead('include/class/alipay.class.php');
if($_p_order['order_paytype']=='alipay'){

$pay= new alipay();
if(!$pay)pe_success('支付方式错误!');
$order['email']=$_p_order['user_email'];
$order['username']=$_s_user_name.$act;
$order['url_r']=PAY_SITE.'pay.php?act=geturl';
$order['url_n']=PAY_SITE.'pay.php?act=posturl';
$order['order_amount']=sprintf("%.2f",round($_p_order['order_money']*(1+$pay->payment['alipay_rate']/100),2));
$order['order_sn']=date('YmdHis',TIME).random(6,'0123456789');
$order['subject']='购买产品:'.$_p_order['order_name'];
$pay_online = $pay->get_code($order);
if($pay_online){
$add['out_trade_no']=$order['order_sn'];
$add['total_fee']=$order['order_amount'];
$add['payment_type']=$_SESSION['payment_type'];
$add['type']='product';
$add['rec']=$order_id;
$add['inputtime']=TIME;
$add['status']=1;
$r=$db->pe_insert('alipay_log', pe_dbhold($add));
if(!$r)pe_alert('支付初始化失败,请重新下单!');
}
include(pe_tpl('send_alipay.html'));
}
else{
if(finish_order($order_id));
pe_alert('下单已经完成','user.php?mod=package&act=tg');
//header('location:'.PAY_SITE.'pay.php?act=finish&id='.$order_id);
}
break;
case 'geturl':
p('这是一个未知错误,或许是支付宝改变了返回模式');
break;
case 'posturl':
pe_lead('include/class/alipay.class.php');
$pay = new alipay();



if(isset($pay))
{
$result = $pay->respond();

if($result)
{
if(strpos($_GET['subject'],'getpost')=="")
{
$r=$pay->respond();
if($r){
if($_g_total_fee<=0)pe_alert('充值金额为0');
if(!$_g_out_trade_no)pe_alert('无正确的充值验证');
$remark='在线充值';
$r=amount($_s_user_name,$_g_total_fee,$remark,'alipay');
if($r){
$db->pe_update('alipay_log',array('out_trade_no'=>$_g_out_trade_no),array('status'=>9));
pe_alert('在线充值成功','user.php?mod=setting&act=base');
}
}
else pe_alert($pay->err,'user.php?mod=pay&act=cash');
}

$_p=$db->pe_select('order',array('order_id'=>$result));
$up['order_state']='paid';
$up['order_ptime']=TIME;
$pro=$db->pe_select('product',array('package_id'=>$_p['package_id']));
if($pro['downurl']){
$up['order_state']='success';
$up['order_stime']=TIME;
}
$r=$db->pe_update('order',array('order_id'=>$result),$up);
if($r)$r=$db->pe_update('alipay_log',array('out_trade_no'=>$_g_out_trade_no),array('status'=>9));
if(finish_order($result));
pe_alert('支下单已经完成了!','user.php?mod=package&act=tg');
}
else pe_alert($pay->err,'user.php');

}
else pe_alert('支付宝初始化失败!','user.php');
break;
default :
header('location:'.PAY_SITE);
}
function finish_order($id){
global $db;
$_p=$db->pe_select('order',array('order_id'=>$id));
if(empty($_p))return false;
$_p['order_atime']=TIME;
$r=$db->pe_select('product',array('package_id'=>$_p['package_id']));
if($_p['order_id']){
//订单邮件
$info['order_name'] = $_p['order_name']; 
$info['order_money']= $_p['order_money'];
$info['order_text']= $_p['order_text'];
$info['user_tname']= $_p['user_tname'];
$info['user_email']= $_p['user_email'];
$info['user_address']=$_p['user_address'];

if($_p['order_state']=='send'){
if($downurl){
$st='sendv';
$info['downurl']=$downurl;
}
else $st='send';
}
elseif($_p['order_state']=='paid')$st='pay';
else $st='add';

pe_lead('hook/order.hook.php');
$email['qunfa_name'] = orderemail($st,'name',$info);
$email['qunfa_text'] = orderemail($st,'text',$info);

$user['user_name'] = $info['user_tname'];
$user['user_email'] = $info['user_email'];
pe_lead('hook/qunfa.hook.php');
qunfa_emailone($email, $user);

if($_p['order_state']=='success'){
//准备给会员发奖金,支付宝付款的虚拟产品,直接交易成功
pe_lead('include/function/tjuser.func.php');
ms_tj_pro($id);
}
return true;
}
return false;
}
?>

我的程序有一个充值的地方和一个订单系统,这个是支付宝回调的页面,本来应该是充值后显示充值成功,下单后显示下单成功,判断哪里有问题,现在不管下订单还是充值后 都是充值成功,请问大神是哪里的问题?




加载中
返回顶部
顶部