成人无码黄动漫在线播放,亚洲国产精品一区二区色迷迷影院,欧美日本国产一区,99热只有这里有精品

首頁(yè)

如何調(diào)用支付寶支付接口的實(shí)現(xiàn)

支付寶支付 2018-05-07 5114

對(duì)于任何一款軟件來(lái)說(shuō),支付功能都是核心的,那么目前的主流支付接口主要是支付寶、微信和銀聯(lián)卡,而大多數(shù)開(kāi)發(fā)技術(shù)人員對(duì)于如何調(diào)用支付寶的支付接口還存在很大的困擾,今天app開(kāi)發(fā)報(bào)價(jià)燚軒科技就來(lái)跟大家分享一下如何正確調(diào)用支付寶支付接口的實(shí)現(xiàn),代碼如下所示:

   public function zfbpay1(){

        require_once './ThinkPHP/Extend/Vendor/alipay1/config.php';

        require_once './ThinkPHP/Extend/Vendor/alipay1/pagepay/service/AlipayTradeService.php';

        require_once './ThinkPHP/Extend/Vendor/alipay1/pagepay/buildermodel/AlipayTradePagePayContentBuilder.php';

        $model=M('zfbpay');

        $add['oid']=I('nid');

        $add['type']=1;

        $add['WIDout_trade_no']=trim($_POST['WIDout_trade_no']);

        $add['WIDtotal_amount']=trim($_POST['WIDtotal_amount']);

        $add['WIDsubject']=trim($_POST['WIDsubject']);

        // dump($_POST);die;

        $re=$model->add($add);

        if($re){

            //商戶訂單號(hào),商戶網(wǎng)站訂單系統(tǒng)中唯一訂單號(hào),必填

            $out_trade_no = trim($_POST['WIDout_trade_no']);

            //訂單名稱(chēng),必填

            $subject = trim($_POST['WIDsubject']);

            //付款金額,必填

            // $total_amount = trim($_POST['WIDtotal_amount']);

            $total_amount = 0.01;

            //商品描述,可空

            $body = trim($_POST['WIDbody']);

            //構(gòu)造參數(shù)

            $payRequestBuilder = new AlipayTradePagePayContentBuilder();

            $payRequestBuilder->setBody($body);

            $payRequestBuilder->setSubject($subject);

            $payRequestBuilder->setTotalAmount($total_amount);

            $payRequestBuilder->setOutTradeNo($out_trade_no);

 

            $aop = new AlipayTradeService($config);

 

          /**

           * pagePay 電腦網(wǎng)站支付請(qǐng)求

           * @param $builder 業(yè)務(wù)參數(shù),使用buildmodel中的對(duì)象生成。

           * @param $return_url 同步跳轉(zhuǎn)地址,公網(wǎng)可以訪問(wèn)

           * @param $notify_url 異步通知地址,公網(wǎng)可以訪問(wèn)

           * @return $response 支付寶返回的信息

          */

          $response = $aop->pagePay($payRequestBuilder,$config['return_url'],$config['notify_url']);

          $map['nid']=I('nid');

          $map['out_trade_no']=$out_trade_no;

            M('need')->save($map);

 

          //輸出表單

          var_dump($response);          

        }

}

 

回調(diào)

    public function updatezfb(){

        require_once './ThinkPHP/Extend/Vendor/alipay1/config.php';

        require_once './ThinkPHP/Extend/Vendor/alipay1/pagepay/service/AlipayTradeService.php';

        $arr=$_POST;

        $alipaySevice = new AlipayTradeService($config);

 

        $alipaySevice->writeLog(var_export($_POST,true));

        $result = $alipaySevice->check($arr);

        /* 實(shí)際驗(yàn)證過(guò)程建議商戶添加以下校驗(yàn)。

        1、商戶需要驗(yàn)證該通知數(shù)據(jù)中的out_trade_no是否為商戶系統(tǒng)中創(chuàng)建的訂單號(hào),

        2、判斷total_amount是否確實(shí)為該訂單的實(shí)際金額(即商戶訂單創(chuàng)建時(shí)的金額),

        3、校驗(yàn)通知中的seller_id(或者seller_email) 是否為out_trade_no這筆單據(jù)的對(duì)應(yīng)的操作方(有的時(shí)候,一個(gè)商戶可能有多個(gè)seller_id/seller_email

        4、驗(yàn)證app_id是否為該商戶本身。

        */

        if($result) {//驗(yàn)證成功

          /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

          //請(qǐng)?jiān)谶@里加上商戶的業(yè)務(wù)邏輯程序代

          // $add['content']=$_POST['out_trade_no'];

          // M('a')->add($add);

          // $add['content']=json_encode($_POST);

          // M('a')->add($add);

 

          

          //——請(qǐng)根據(jù)您的業(yè)務(wù)邏輯來(lái)編寫(xiě)程序(以下代碼僅作參考)——

          

            //獲取支付寶的通知返回參數(shù),可參考技術(shù)文檔中服務(wù)器異步通知參數(shù)列表

          

          //商戶訂單號(hào)

 

          $out_trade_no = $_POST['out_trade_no'];

 

          //支付寶交易號(hào)

 

          $trade_no = $_POST['trade_no'];

 

          //交易狀態(tài)

          $trade_status = $_POST['trade_status'];

 

 

            if($_POST['trade_status'] == 'TRADE_FINISHED') {

                $zfbmodel=M('zfbpay');

                $arr=$zfbmodel->where("WIDout_trade_no=$out_trade_no")->find();

                if($arr){

                    $type=$arr['type'];//1購(gòu)買(mǎi)商品 2充值余額 3做單支付

                    if($type==1){

                        //購(gòu)買(mǎi)商品

                        $nid=$arr['id'];

                        $model=M('need');

                        $orderinfo=$model->where("nid=$nid")->find();

                       $tuoguan=$orderinfo['tuoguan'];

                        $province=$orderinfo['province'];

                        $finish_state=$orderinfo['finish_state'];

                        $arr1['tuoguan']=1;

                        if($finish_state==1){

                           $arr1['finish_state']=2;

                        }

                        if ($orderinfo['money']!=0) {

                           $arr1['money']=$orderinfo['money'];

                           

                        }else{

                           $arr1['money']=intval($orderinfo['money'])+intval($arr['WIDtotal_amount']);

                        }

                        $arr1['paytype']=1;

                        $res=$model->save($arr1);

                    }elseif($type==2){

                        //余額充值

                        $rid=$arr['id'];

                        //獲取充值信息

                        $model=M('recharge');

                        $usermodel=M('user');

                        $rechargeinfo=$model->where("rid=$rid")->find();

                        $paystate=$rechargeinfo['paystate'];

                        if($paystate==0){

                            $uid=$rechargeinfo['uid'];

                            $num=$rechargeinfo['amoney'];      

                              //更新訂單狀態(tài)

                            $update['paystate']=1;

                            $res=$model->where("rid=$rid")->save($update);            

                            if($res){

                                //更新用戶余額

                                $re2=$usermodel->where("id=$uid")->setInc('yue',$num);

                            }

                        }                        

                    }elseif($type==3){

                        

                     

                    }

                }

            //判斷該筆訂單是否在商戶網(wǎng)站中已經(jīng)做過(guò)處理

              //如果沒(méi)有做過(guò)處理,根據(jù)訂單號(hào)(out_trade_no)在商戶網(wǎng)站的訂單系統(tǒng)中查到該筆訂單的詳細(xì),并執(zhí)行商戶的業(yè)務(wù)程序

              //請(qǐng)務(wù)必判斷請(qǐng)求時(shí)的total_amount與通知時(shí)獲取的total_fee為一致的

              //如果有做過(guò)處理,不執(zhí)行商戶的業(yè)務(wù)程序

                

            //注意:

            //退款日期超過(guò)可退款期限后(如三個(gè)月可退款),支付寶系統(tǒng)發(fā)送該交易狀態(tài)通知

            }

            else if ($_POST['trade_status'] == 'TRADE_SUCCESS') {

                $zfbmodel=M('zfbpay');

                $arr=$zfbmodel->where("WIDout_trade_no=$out_trade_no")->find();

                if($arr){

                    $type=$arr['type'];//1購(gòu)買(mǎi)商品 2充值余額 3做單支付

                    if($type==1){

                        //購(gòu)買(mǎi)商品

                        $oid=$arr['id'];

                        $model=M('order_goods');

                        $orderinfo=$model->where("oid=$oid")->find();

                        $paystate=$orderinfo['paystate'];

                        if($paystate==0){

                            $update['paystate']=1;

                            $res=$model->where("oid=$oid")->save($update);

                            

                            //更新惠點(diǎn)

                        $umod=M('user');

                        $ordersone=$model->where("oid=$oid")->find();

                        $uid=$ordersone['uid'];

                        $usertel=$umod->where("id=$uid")->find();

                        $sys=M('sys')->find();     

                        $mmp['id']=$usertel['id'];      

                        $mmp['money']=$usertel['money']+$ordersone['oprice'];

                        $mmp['huidian']=floor($mmp['money']/$sys['zshd']);

                        $userSave=$umod->save($mmp);

                        }

                    }elseif($type==2){

                        //余額充值

                        $rid=$arr['id'];

                        //獲取充值信息

                        $model=M('recharge');

                        $usermodel=M('user');

                        $rechargeinfo=$model->where("rid=$rid")->find();

                        $paystate=$rechargeinfo['paystate'];

                        if($paystate==0){

                            $uid=$rechargeinfo['ui

分享到微信朋友圈 +
打開(kāi)微信,點(diǎn)擊底部的“發(fā)現(xiàn)”,使用 “掃一掃” 即可將網(wǎng)頁(yè)分享到我的朋友圈。 如何使用?
推薦文章

熱貼More +

服務(wù)范圍More +

聯(lián)系我們

請(qǐng)掃二維碼聯(lián)系客服

854221200@qq.com

185-3825-9583

QQ客服

關(guān)于  ·  招聘  ·  案例中心  ·  網(wǎng)站地圖

?@2018 燚軒科技版權(quán)所有 豫ICP備16015002號(hào)-4

百度提供搜索支持