zoukankan      html  css  js  c++  java
  • html中的js监听付款按钮--触发ajax调用php后台--得到的json数据---交给安卓原生处理

    //01
      var pay_status = new Object();
    $(".sure_pay").on("touchstart",function(){

    var order_id = $('#order_id').val();


    payLinkShape("showShape");
    var payType=1;//默认是微信支付,用来储存支付象征标识
    /*点击获取支付方式start*/
    $('.payBox input').on('ifChecked', function(event){
    if(event.type == "ifChecked"){
    clsName=$(this).attr("class");
    }
    })
    /*点击获取支付方式end*/
    switch (clsName)
    {
    case "weix":
    payType=1;
    break;
    case "zfb":
    payType=2;
    break;
    case "company":
    payType=0;
    break;
    }

    //console.log('clsName ==');
    //console.log(clsName);
    //console.log('order_id ='+order_id);
    $.ajax({
    url:"/order/pay_order_wx?order_id="+order_id,
    type:'GET',
    data:"{}",
    dataType:"json",
    success: function(jsonPayinfo){
    console.log('success ==');
    console.log(jsonPayinfo);
    if(jsonPayinfo.return_code == 'SUCCESS' && jsonPayinfo.result_code == 'SUCCESS')
    {
    jsonPayinfo=JSON.stringify(jsonPayinfo);
    //console.log(jsonPayinfo);
    payLinkShape();
    var u = navigator.userAgent;
    //TripMobile.tripPay(payType,jsonPayinfo);
    if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
    //安卓手机
    TripMobile.tripPay(payType,jsonPayinfo);
    //console.log(payType);
    //console.log(jsonPayinfo);
    } else if (u.indexOf('iPhone') > -1) {
    //苹果手机
    //jakilllog(payType,jsonPayinfo);
    }
    }else{
    console.log('进来这里了');
    return false;
    }
    }, error: function (XMLHttpRequest, textStatus, errorThrown) {
    //console.log('error +++');
    //console.log(XMLHttpRequest);
    //console.log(textStatus);
    //console.log(errorThrown);


    }
    });

    })






    ////////////02调用微信支付
    public function pay_order_wx($order_id)
    {

    $orderModel = M("order");
    $get_data = I('get.');

    $where['order_id'] = $get_data['order_id'];
    $orderinfo = $orderModel->where($where)->find();

    require_once( APP_PATH."../thinkphp/ThinkPHP/Library/Vendor/WxPay/lib/WxPay.Api.php");
    require_once( APP_PATH."../thinkphp/ThinkPHP/Library/Vendor/WxPay/lib/WxPay.Config.php");
    require_once( APP_PATH."../thinkphp/ThinkPHP/Library/Vendor/WxPay/lib/WxPay.Data.php");
    require_once( APP_PATH."../thinkphp/ThinkPHP/Library/Vendor/WxPay/lib/WxPay.Exception.php");
    require_once( APP_PATH."../thinkphp/ThinkPHP/Library/Vendor/WxPay/JsApiPay.php");

    //$tools = new JsApiPay();
    //$openId = $tools->GetOpenid();
    //②、统一下单

    $input = new WxPayUnifiedOrder();
    $input->SetBody( '差旅费用');
    $input->SetAttach("test");
    $input->SetOut_trade_no( $orderinfo['order_num'].date("YmdHis") );//8位订单号,加上14位时间

    if( TRIP_MODE == 'DEV' || TRIP_MODE == 'TEST' ){
    $input->SetTotal_fee("1");//开发环境,和测试环境.默认付款0.01元
    }else{
    $input->SetTotal_fee( $orderinfo['order_true_total_money'] * 100 ); //微信支付以分为单位。
    }
    //我们数据库100.16元.会被转成 100.16分

    $input->SetTime_start(date("YmdHis"));
    $input->SetTime_expire(date("YmdHis", time() + 600));
    $input->SetGoods_tag("test");

    $input->SetNotify_url( "http://{$_SERVER['HTTP_HOST']}/api/wxpay/on_wxpay_complete.html");
    $input->SetTrade_type("APP");
    $order = WxPayApi::unifiedOrder($input);

    $timeStamp = time();
    $returnorder['appid'] = "wx9xxxxxx4f7dde7";
    $returnorder['partnerid'] = "13999999991";
    $returnorder['noncestr'] = md5($order['nonce_str']);
    $returnorder['timestamp'] = $timeStamp;
    $returnorder['prepayid'] = $order['prepay_id'];
    $returnorder['package'] = "Sign=WXPay";

    //签名步骤一:
    ksort($returnorder);
    $sign = "";
    foreach ($returnorder as $k => $v)
    {
    if($k != "sign"){
    $sign .= $k . "=" . $v . "&";
    }
    }
    $sign = trim($sign, "&");

    //签名步骤二:在string后加入KEY
    $sign = $sign . "&key=".WxPayConfig::KEY;
    //$sign = $sign . "&key=".'xxxxxxxxxxx';

    //签名步骤三:MD5加密
    $sign = md5($sign);
    //签名步骤四:所有字符转为大写
    $sign = strtoupper($sign);
    $returnorder['sign'] = $sign;

    $returnorder['return_code'] = $order['return_code'];
    $returnorder['return_msg'] = 'OK';
    $returnorder['result_code'] = $order['result_code'];
    D('Tlog')->log( "微信支付订单 orderid=".$order_id. ' result'.json_encode_ex($order) );
    $this->ajaxReturn($returnorder,'json');

    }


    ////////03接收微信回调
    public function on_wxpay_complete(  )
    {
    // $info = $_REQUEST;

    if( APP_DEBUG ) ThinkLog::write('WxNotify: RAW_POST: '.$GLOBALS["HTTP_RAW_POST_DATA"], 'DEBUG' );

    $rowpost = $GLOBALS["HTTP_RAW_POST_DATA"];

    vendor('XmlParser.XML','','.class.php');

    $qr = XML_unserialize( $rowpost );

    mylog1('$qr =='.json_encode_ex($qr));

    //记录日志,将所有的第三方通知消息都记录日志
    $curtime = date('Ymd H:i:s');
    $ordernumber = $qr['xml']['out_trade_no'];
    $ordernumber = substr( $qr['xml']['out_trade_no'], 0, 12 );
    file_put_contents( C('LOGPATH_ORDER_NITIFY')."/Wxpay_{$ordernumber}.txt", " $curtime ".json_encode_ex($qr),FILE_APPEND );

    /*
    array(1) {
    ["xml"] => array(17) {
    ["appid"] => string(18) "wx9999999dde7"
    ["attach"] => string(4) "test"
    ["bank_type"] => string(3) "CFT"
    ["cash_fee"] => string(1) "1"
    ["fee_type"] => string(3) "CNY"
    ["is_subscribe"] => string(1) "N"
    ["mch_id"] => string(10) "1346077501"
    ["nonce_str"] => string(32) "ermeg0d01gv7k4aqppwrmtqfn1yohgy0"
    ["openid"] => string(28) "ok4np999999b7X90JmwDc"
    ["out_trade_no"] => string(26) "20160524010520160526193042"
    ["result_code"] => string(7) "SUCCESS"
    ["return_code"] => string(7) "SUCCESS"
    ["sign"] => string(32) "0ECB9999999DF9B859C45"
    ["time_end"] => string(14) "20160526193052"
    ["total_fee"] => string(1) "1"
    ["trade_type"] => string(3) "APP"
    ["transaction_id"] => string(28) "4099999999993752"
    }
    }
    */

    if( 'SUCCESS' == $qr['xml']['result_code'] && 'SUCCESS' == $qr['xml']['return_code'] )
    {

    //支付成功






  • 相关阅读:
    正经学C#_循环[do while,while,for]:[c#入门经典]
    Vs 控件错位 右侧资源管理器文件夹点击也不管用,显示异常
    asp.net core 获取当前请求的url
    在实体对象中访问导航属性里的属性值出现异常“There is already an open DataReader associated with this Command which must be
    用orchard core和asp.net core 3.0 快速搭建博客,解决iis 部署https无法登录后台问题
    System.Data.Entity.Core.EntityCommandExecution The data reader is incompatible with the specified
    初探Java设计模式3:行为型模式(策略,观察者等)
    MySQL教程77-CROSS JOIN 交叉连接
    MySQL教程76-HAVING 过滤分组
    MySQL教程75-使用GROUP BY分组查询
  • 原文地址:https://www.cnblogs.com/bj-tony/p/5783251.html
Copyright © 2011-2022 走看看