1. 程式人生 > >微信支付和支付寶支付接口回調函數的判斷

微信支付和支付寶支付接口回調函數的判斷

判斷 遍歷 節點數據 task har 支付 節點數 怎麽 yun

微信支付和支付寶支付接口是現在網絡商城必不可少的功能,有些網站不只一處需要對接這樣同一個接口,不同的功能,傳的參數不一樣,但是回調只有一個,針對這樣的問題,我們在回調函數裏就需要進行判斷了,判斷是那個功能模塊傳過來的參數,來進行處理後續問題。下面就來為大家分析解答一下。

  主要實現代碼如下:
接口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開發公司燚軒科技整理發布,如需轉載請註明出處。

微信支付和支付寶支付接口回調函數的判斷