alipay支付接口
2024-11-24 18:54:06
<?php if ($fn_include = $this->_include("header.html", "/")) include($fn_include); ?> <link href="<?php echo HOME_THEME_PATH; ?>/css/news.css" rel="stylesheet"> <link rel="stylesheet" href="{THEME_PATH}js/ui-dialog.css"> <script type="text/javascript" src="/statics/js/layer/layer.js"></script> <style> .main2{ margin-left:auto; position:static; } tr,table{ width:100%; text-align:center; } tr{ padding:0px 0 15px; display:block; /*将tr设置为块体元素*/ margin:0 auto; width:96%; } .line{ border-top:1px solid #dddddd; padding:30px 0 10px; } td{ width:520px; height:32px; padding-left:5px; text-align:center; } td span:nth-child(1){ width:90px; text-align:right; display:inline-block; } tr input,.sub{ width:230px; height:30px; border-radius:5px; border:1px solid gainsboro; background:#f5f5f5; padding-left:10px; margin:0 10px; } .sub{margin-left:127px;width:200px;color:white;background:#108ee9;border:none;height:40px;margin-top:10px;font-size:16px;} tr td:nth-child(1){ text-align:left; } .footer{ margin-top:100px; } </style> <?php if ($fn_include = $this->_include("nav.html", "/")) include($fn_include); ?> </div> <div class="main2" > <div style="width:90%;height:5rem;line-height:5rem;background:#108ee9;margin:10px auto;padding-left:10px;color:white;font-size:16px;"> 填写保单 - <?php echo $get['name']; ?> </div> <form action="/index.php?c=form_baoxianfuwu" class="form-horizontal" method="post" accept-charset="utf-8"> <div style="width:90%;margin:10px auto;"> <table id="" border="0"> <input type="hidden" id="bxmc" value="{$get['name']}" /> <input type="hidden" id="tbbxgsmc" value="{$get['company']}" /> <input type="hidden" id="bxcpid" value="{$get['insid']}" /> <tr class="line"> <td><span>投保人名称</span><input type="datetime" name="data[tbrmc]" id="tbrmc" value="江苏运满舱科技有限公司" readonly/></td> <td><span>被保险人名称</span><input type="datetime" name="data[bbxrmc]" id="bbxrmc" value="" /></td> </tr> <tr> <td><span>联系人</span><input type="datetime" name="data[lianxiren]" id="lianxiren" value="" /></td> <td><span>联系电话</span><input type="datetime" name="data[lxdh]" id="lxdh" value="" /></td> </tr> <tr class="line"> <td><span>发票/运单号</span><input type="datetime" name="data[fpydh]" id="fpydh" value="" /><span style="color:green;">(选填)</span></td> <td><span>数量</span><input type="datetime" name="data[shuliang]" id="shuliang" value="" /><span>吨</span></td> </tr> <tr> <td><span>货物种类</span><input type="datetime" name="data[hwzl]" id="hwzl" value="" /></td> <td><span>货物名称</span><input type="datetime" name="data[hwmc]" id="hwmc" value="" /></td> </tr> <tr class="line"> <td><span>船名</span><input type="datetime" name="data[chuanming]" id="chuanming" value="" /></td> <td><span>联系方式</span><input type="datetime" name="data[lxfs]" id="lxfs" value="" /></td> </tr> <tr> <td><span>起运港</span><input type="datetime" name="data[qiyungang]" id="qiyungang" value="" /></td> <td><span>目的港</span><input type="datetime" name="data[mudegang]" id="mudegang" value="" /></td> </tr> <tr> <td><span>起运日期</span><input type="datetime" name="data[qiyunriqi]" id="qiyunriqi" value="" /><span style="color:red;">(请提前两小时提交表单)</span></td> <td><span>邮寄地址</span><input type="datetime" name="data[youjidizhi]" id="youjidizhi" value="" /></td> </tr> <tr class="line"> <td><span>保险金额</span><input type="datetime" onblur="q()" name="data[baoxianjine]" id="baoxianjine" value="" />元(费率:0.2‰)</td> <td><span>保费</span><input type="datetime" name="data[baofei]" id="baofei" value="" readonly/></td> </tr> </table> <button type="button" onclick="submit_baodan()" class="sub">提交保单</button></br> <input type="checkbox" name="gouxuan" id="gouxuan" value="" style="height:15px;width:272px;margin-top:15px;margin-right:-115px;vertical-align:-3px;" />已阅读并同意《水路货物运输保险条款》、《用户投保须知》 </div> </form> <script> function submit_baodan(id){ var bxmc = $('#bxmc').val(); var tbbxgsmc = $('#tbbxgsmc').val(); var bxcpid = $('#bxcpid').val(); var tbrmc = $('#tbrmc').val(); var bbxrmc = $('#bbxrmc').val(); if(!bbxrmc){ layer.alert('被保险人名称不能为空', { skin: 'demo-class' ,closeBtn: 1 // 是否显示关闭按钮 ,anim: 1 //动画类型 ,btn: ['确定'] //按钮 ,icon: 5 // icon }); return false; } var lianxiren = $('#lianxiren').val(); if(!lianxiren){ layer.alert('联系人不能为空', { skin: 'demo-class' ,closeBtn: 1 // 是否显示关闭按钮 ,anim: 1 //动画类型 ,btn: ['确定'] //按钮 ,icon: 5 // icon }); return false; } var lxdh = $('#lxdh').val(); if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(lxdh))){ layer.alert('请输入正确的手机号码', { skin: 'demo-class' ,closeBtn: 1 // 是否显示关闭按钮 ,anim: 1 //动画类型 ,btn: ['确定'] //按钮 ,icon: 5 // icon }); return false; } var fpydh =$('#fpydh').val(); var shuliang = $('#shuliang').val(); if(!shuliang){ layer.alert('数量不能为空', { skin: 'demo-class' ,closeBtn: 1 // 是否显示关闭按钮 ,anim: 1 //动画类型 ,btn: ['确定'] //按钮 ,icon: 5 // icon }); return false; } var hwzl= $('#hwzl').val(); if(!hwzl){ layer.alert('货物种类不能为空', { skin: 'demo-class' ,closeBtn: 1 // 是否显示关闭按钮 ,anim: 1 //动画类型 ,btn: ['确定'] //按钮 ,icon: 5 // icon }); return false; } var hwmc = $('#hwmc').val(); if(!hwmc){ layer.alert('货物名称不能为空', { skin: 'demo-class' ,closeBtn: 1 // 是否显示关闭按钮 ,anim: 1 //动画类型 ,btn: ['确定'] //按钮 ,icon: 5 // icon }); return false; } var chuanming = $('#chuanming').val(); if(!chuanming){ layer.alert('船名不能为空', { skin: 'demo-class' ,closeBtn: 1 // 是否显示关闭按钮 ,anim: 1 //动画类型 ,btn: ['确定'] //按钮 ,icon: 5 // icon }); return false; } var lxfs = $('#lxfs').val(); if(!lxfs){ layer.alert('联系方式不能为空', { skin: 'demo-class' ,closeBtn: 1 // 是否显示关闭按钮 ,anim: 1 //动画类型 ,btn: ['确定'] //按钮 ,icon: 5 // icon }); return false; } var qiyungang = $('#qiyungang').val(); var mudegang = $('#mudegang').val(); var qiyunriqi = $('#qiyunriqi').val(); var youjidizhi = $('#youjidizhi').val(); var baoxianjine = $('#baoxianjine').val(); if(!baoxianjine){ layer.alert('保险金额不能为空', { skin: 'demo-class' ,closeBtn: 1 // 是否显示关闭按钮 ,anim: 1 //动画类型 ,btn: ['确定'] //按钮 ,icon: 5 // icon }); return false; } var baofei = $('#baofei').val(); var gouxuan =$("#gouxuan").is(":checked"); if(!gouxuan){ layer.alert('请勾选条款', { skin: 'demo-class' ,closeBtn: 1 // 是否显示关闭按钮 ,anim: 1 //动画类型 ,btn: ['确定'] //按钮 ,icon: 5 // icon }); return false; } $.ajax({ type: "POST", url:"/index.php?c=form_baoxianfuwu", data: {"bxmc":bxmc,"tbbxgsmc":tbbxgsmc,"bxcpid":bxcpid,"tbrmc":tbrmc,"bbxrmc":bbxrmc,"lianxiren":lianxiren,"lxdh":lxdh,"fpydh":fpydh,"shuliang":shuliang,"hwzl":hwzl,"hwmc":hwmc,"chuanming":chuanming,"lxfs":lxfs,"qiyungang":qiyungang,"mudegang":mudegang,'qiyunriqi':qiyunriqi,"youjidizhi":youjidizhi,"baoxianjine":baoxianjine,"baofei":baofei,'order_status':0}, dataType: 'json', success: function(msg) { if(msg.status){ layer.msg('提交成功'); setTimeout(function () { location.href = 'http://www.ymc56.cn/index.php?c=pay&m=index&form=baoxianfuwu&id='+msg.id; }, 1000); }else{ layer.msg('<font color=red>'+msg.code+'</font>', 3); } }, error:function(error){ alert("error"); } }); } function q(){ var baoxianjine = $('#baoxianjine').val(); $('#baofei').val(baoxianjine*0.0002); } </script> <script> $('.hyzx2').addClass("active"); $('.hyzx').mouseenter(function(){ $('.hyzx').addClass("active"); $('.hyzx2').removeClass("active"); $('.hyzx1').removeClass("active"); }) $('.hyzx1').mouseenter(function(){ $('.hyzx1').addClass("active"); $('.hyzx2').removeClass("active"); $('.hyzx').removeClass("active"); }) </script> </div> <?php if ($fn_include = $this->_include("footer.html", "/")) include($fn_include); ?> <script> $(".hk").css("left",750) var hk $(".dhx").mouseenter(function(){ hk = $(this).index(); $(".hk").stop().animate({left:hk*150},300); }).mouseleave(function(){ $(".hk").stop().animate({left:750},300); }) </script>
<?php require_once FCPATH.'branch/fqb/D_Form.php'; class Form_baoxianfuwu extends D_Form { public function __construct() { parent::__construct(); } public function index() { $uid = $this->uid; $member = dr_member_info($uid); $username = $member['username']; $data = $this->input->post(); $data['uid']=$uid; $data['author']=$username; $data['inputip'] = $this->input->ip_address(); $data['inputtime'] = SYS_TIME; $result = $this->db->insert('imt_1_form_baoxianfuwu', $data); $id = $this->db->insert_id(); if($result){ exit(json_encode(['status' => 1, 'id' => $id,'message'=>'订单提交成功'])); }else{ exit(json_encode("数据提交失败")); } } }
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); /* v3.2.0 */ class Pay extends M_Controller { /** * 构造函数 */ public function __construct() { parent::__construct(); } public function msg() { $this->template->assign(array( 'msg' => '提示信息' )); $this->template->display('msg.html'); } public function index(){ if($_GET['form']=="apply"){ //培训课程 $form = $this->db->where('id', $_GET['id'])->get('3_form_'.$_GET['form'])->row_array(); } elseif ($_GET['form']=="gongyouyewu"){ //供油业务 $form = $this->db->where('id', $_GET['id'])->get('imt_1_form_gongyouyewu')->row_array(); } elseif ($_GET['form']=="baoxianfuwu"){ //保险服务 $form = $this->db->where('id', $_GET['id'])->get('1_form_'.$_GET['form'])->row_array(); } switch ($_GET['form']) { case 'apply': $course = $this->db->where('id', $form['courseid'])->get('imt_3_course')->row_array(); $money = $course['price']; $title = '课程【'.$course['title'].'】费用'; break; case 'gongyouyewu': $gongyouyewu = $this->db->where('id', $form['youpinid'])->get('imt_1_oiloffer')->row_array(); $money = $form['zongfeiyong']; $title = '供油【'.$gongyouyewu['title'].'】费用'; break; case 'baoxianfuwu': $baoxianfuwu = $this->db->where('id', $form['id'])->get('imt_1_form_baoxianfuwu')->row_array(); $money = $baoxianfuwu['baofei']; $title = '保险【'.$baoxianfuwu['bxmc'].'】费用'; break; default: // code... break; } if(IS_AJAX){ $this->db->insert('member_paylog', array( 'uid' => $this->uid, 'type' => 'alipay', 'note' => $title, 'order' => $_GET['id'], 'value' => $money, 'module' => $_GET['form'], 'status' => 0, 'inputtime' => SYS_TIME )); $insert_id = $this->db->insert_id(); if($insert_id){ echo 'http://www.ymc56.cn/index.php?c=pay&m=pay&id='.$insert_id; } } else { $this->template->assign(array( 'title' => $title, 'money' => $money )); $this->template->display('pay.html'); } } public function pay(){ $id = $_GET['id']; $order = $this->db->where('id', $id)->get('member_paylog')->row_array(); $pay = $order['type']; $title = $order['note']; $sn = "FC-{$id}-".$this->uid.'-'.$order['module'].'-'.$order['order']; $money = $order['value']; $result = NULL; require_once WEBPATH.'api/pay/'.$pay.'/pay.php'; echo $result['form']; } }
<?php $pay = require WEBPATH.'api/pay/alipay/config.php'; $alipay_config['key'] = $pay['key']; $alipay_config['partner'] = $pay['id']; $alipay_config['sign_type'] = 'MD5'; $alipay_config['transport'] = 'http'; $alipay_config['return_url'] = SITE_URL.'api/pay/alipay/return_url.php'; $alipay_config['notify_url'] = SITE_URL.'api/pay/alipay/notify_url.php'; $alipay_config['input_charset']= 'utf-8'; $alipay_config['seller_email'] = $pay['username']; if ($this->mobile && $pay['wap']) { // 手机接口 $alipay_config['return_url'] = SITE_URL.'api/pay/alipay/wap_return_url.php'; $alipay_config['notify_url'] = SITE_URL.'api/pay/alipay/wap_notify_url.php'; require_once(WEBPATH.'api/pay/alipay/wap/alipay_submit.class.php'); /**************************调用授权接口alipay.wap.trade.create.direct获取授权码token**************************/ //返回格式 $format = "xml"; $v = "2.0"; $req_id = date('Ymdhis').rand(0, 9999); //必填,须保证每次请求都是唯一 //**req_data详细信息** $notify_url = $alipay_config['notify_url']; $call_back_url = $alipay_config['return_url']; $merchant_url = SITE_URL; $seller_email = $alipay_config['seller_email']; $out_trade_no = $sn; $subject = $title; $total_fee = $money; $req_data = '<direct_trade_create_req><notify_url>' . $notify_url . '</notify_url><call_back_url>' . $call_back_url . '</call_back_url><seller_account_name>' . $seller_email . '</seller_account_name><out_trade_no>' . $out_trade_no . '</out_trade_no><subject>' . $subject . '</subject><total_fee>' . $total_fee . '</total_fee><merchant_url>' . $merchant_url . '</merchant_url></direct_trade_create_req>'; /************************************************************/ //构造要请求的参数数组,无需改动 $para_token = array( "service" => "alipay.wap.trade.create.direct", "partner" => trim($alipay_config['partner']), "sec_id" => trim($alipay_config['sign_type']), "format" => $format, "v" => $v, "app_pay" => "Y", "req_id" => $req_id, "req_data" => $req_data, "_input_charset" => trim(strtolower($alipay_config['input_charset'])) ); //建立请求 $alipaySubmit = new AlipaySubmit($alipay_config); $html_text = $alipaySubmit->buildRequestHttp($para_token); //URLDECODE返回的信息 $html_text = urldecode($html_text); //解析远程模拟提交后返回的信息 $para_html_text = $alipaySubmit->parseResponse($html_text); //获取request_token $request_token = $para_html_text['request_token']; /**************************根据授权码token调用交易接口alipay.wap.auth.authAndExecute**************************/ $req_data = '<auth_and_execute_req><request_token>' . $request_token . '</request_token></auth_and_execute_req>'; //构造要请求的参数数组,无需改动 $parameter = array( "service" => "alipay.wap.auth.authAndExecute", "partner" => trim($alipay_config['partner']), "sec_id" => trim($alipay_config['sign_type']), "format" => $format, "v" => $v, "req_id" => $req_id, "req_data" => $req_data, "_input_charset" => trim(strtolower($alipay_config['input_charset'])) ); //建立请求 $alipaySubmit = new AlipaySubmit($alipay_config); $result['form'] = $alipaySubmit->buildRequestForm($parameter, 'get', '确认'); } else { // PC 接口 require WEBPATH.'api/pay/alipay/alipay_submit.class.php'; require WEBPATH.'api/pay/alipay/alipay_service.class.php'; /**************************请求参数**************************/ //构造要请求的参数数组 $parameter = array( 'service' => 'create_direct_pay_by_user', 'payment_type' => '1', 'partner' => trim($alipay_config['partner']), '_input_charset' => trim(strtolower($alipay_config['input_charset'])), 'seller_email' => trim($alipay_config['seller_email']), 'return_url' => trim($alipay_config['return_url']), 'notify_url' => trim($alipay_config['notify_url']), 'out_trade_no' => $sn, 'subject' => $title, 'body' => fc_lang('会员(%s)支付订单ID:%s', $this->member['username'], $id), 'total_fee' => $money, ); //构造即时到帐接口 $alipayService = new AlipayService($alipay_config); $result['form'] = $alipayService->create_direct_pay_by_user($parameter); }