[已删除]
[已删除]
  • 发布:2018-07-17 17:23
  • 更新:2018-07-17 17:23
  • 阅读:2414

微信支付和支付宝支付接口回调函数的判断

分类:HTML5+

  微信支付和支付宝支付接口是现在网络商城必不可少的功能,有些网站不只一处需要对接这样同一个接口,不同的功能,传的参数不一样,但是回调只有一个,针对这样的问题,我们在回调函数里就需要进行判断了,判断是那个功能模块传过来的参数,来进行处理后续问题。下面就来为大家分析解答一下。

  主要实现代码如下:
接口1:
public function wxpay(){
header("Content-type:text/html;charset=utf-8");
$order_sn=I("order_sn");
$fa_need=M('fa_need');
$list=$fa_need->where("order_sn=$order_sn")->find();
$type=$list['type'];
$price=$list['need_salary'];
ini_set('date.timezone','Asia/Shanghai');
$time = date('Y-m-d');
vendor("WxPayPubHelper.lib.WxPay#Api");
$uid=session("uid");
$user=M("user");
$userinfo=$user->where("uid=$uid")->find();

$openid=$userinfo['openid'];
$data=$type.';'.'1'.';'.$order_sn;
//②、统一下单
$input = new \WxPayUnifiedOrder();

// dump($input);die;
$input->SetBody('欧克帮');
$input->SetAttach($data);
$input->SetOut_trade_no($order_sn); //商户号加上年月日十分秒 订单号
$input->SetTotal_fee($price);
// $input->SetTotal_fee(1);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag($data);
$input->SetNotify_url("http://www.okxiaoyuan.com/Task/updateYanbao");
$input->SetTrade_type("JSAPI");
$input->SetOpenid($openid);

$order = \WxPayApi::unifiedOrder($input);

$jsApiParameters = $this->GetJsApiParameters($order);
// var_dump($jsApiParameters);exit;
$this->assign('price',$price);
$this->assign('order_sn',$order_sn);
$this->assign('openid',$openid);
$this->assign('jsApiParameters',$jsApiParameters);
$this->display();

}
接口2:
public function wxpay1(){
header("Content-type:text/html;charset=utf-8");
$uid=I("uid");
$user=M('user');
$list=$user->where("uid=$uid")->find();
$openid=$list['openid'];
$price=$list['pay_money'];
ini_set('date.timezone','Asia/Shanghai');
$time = date('Y-m-d');
vendor("WxPayPubHelper.lib.WxPay#Api");

$data=$type.';'.'2'.';'.$uid;
$order_sn=date("YmdHis",time()).rand(10000,99999);
//②、统一下单
$input = new \WxPayUnifiedOrder();

// dump($input);die;
$input->SetBody('欧克帮');
$input->SetAttach($data);
$input->SetOut_trade_no($order_sn); //商户号加上年月日十分秒 订单号
$input->SetTotal_fee($price*100);
//$input->SetTotal_fee(1);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag($data);
$input->SetNotify_url("http://www.okxiaoyuan.com/User/updateYanbao");
$input->SetTrade_type("JSAPI");
$input->SetOpenid($openid);

$order = \WxPayApi::unifiedOrder($input);

$jsApiParameters = $this->GetJsApiParameters($order);
// var_dump($jsApiParameters);exit;
$this->assign('price',$price);
$this->assign('order_sn',$order_sn);
$this->assign('openid',$openid);
$this->assign('jsApiParameters',$jsApiParameters);
$this->display();

}
回调:
public function updateYanbao(){
$fileContent = file_get_contents("php://input");
//转换为simplexml对象
$xmlResult = simplexml_load_string($fileContent);
//$arr = json_decode(json_encode($xmlResult),TRUE);
//echo $xmlResult["age"]."//".$xmlResult->age;
if ($xmlResult->result_code=="SUCCESS") {
echo 'SUCCESS';
foreach($xmlResult->children() as $childItem){ //遍历所有节点数据
//输出xml节点名称和值
//echo $childItem->getName() . "->".$childItem."<br />";
//$res = $childItem->getName().":".$childItem.",".$res;
$datas = $childItem.",".$datas;
// $arr['"'.$childItem->getName().'"']=$childItem;
//其他操作省略
}
$varJson = $xmlResult->attach;
$varStr = explode(",", $varJson);
$str=$varStr[0];
$data=explode(';', $str);

    $type=$data[1];  
    if($type==1){  
    $order_sn = $data[2];  
    $model=M('fa_need');  
    $arr=$model->where("order_sn=$order_sn")->find();  
    $uid=$arr['uid'];  
  if($arr){  
  // $user=M("user");  
  // $userinfo=$user->where("uid=$uid")->find();  
  // if($arr['status']==1){  
  // $up['balance_money']=$userinfo['balance_money']+$arr['need_salary'];  
  // $user->where("uid=$uid")->save($up);  
  // }  
  $update1['needpay_state']=2;  
  $update1['status']=2;  
    if($model->where("order_sn=$order_sn")->save($update1)){  
    echo 'SUCCESS';  
    }  
  }  

    }  

    echo 'SUCCESS';  
}  

}

  看完之后估计大部分的程序技术人员应该很清楚是怎么一回事了吧,如果还存在有不理解的地方,大家可以留言咨询。

  本文由专业的郑州app开发公司燚轩科技整理发布,如需转载请注明出处。

0 关注 分享

要回复文章请先登录注册