zoukankan      html  css  js  c++  java
  • php富友接口对接http请求

    1.以余额接口来举例子,当时测试使用的是http请求,后来正式上线之后不好用,我就用了curl

    //获取富友余额开始
    $user_name = $_SESSION['user_name'] ? $_SESSION['user_name'] : '';

    //0001000F0394632
    //0001000F0096241
    $mchnt_cd= '0001000F0394632';
    $mchnt_txn_ssn = date('ymd').substr(time(),-5).substr(microtime(),2,5);
    $mchnt_txn_dt=date("Ymd");
    $cust_no= $user_name;
    $data =$cust_no."|".$mchnt_cd."|".$mchnt_txn_dt."|".$mchnt_txn_ssn;

    $private_key_path = "../modules/php_prkey.pem";
    $signature = rsaSign($data, $private_key_path);




    function rsaSign($data, $private_key_path) {

    $priKey = file_get_contents($private_key_path);

    $res = openssl_get_privatekey($priKey);

    openssl_sign($data, $sign, $res);
    openssl_free_key($res);
    //base64编码
    $sign = base64_encode($sign);

    return $sign;
    }

    //include_once('HttpClient.class.php');
    //目标主机的地址,我这里填上测试的地址
    //$Client = new HttpClient("https://jzh-test.fuiou.com/jzh/BalanceAction.action");
    //https://jzh-test.fuiou.com/jzh/BalanceAction.action
    //https://jzh.fuiou.com/BalanceAction.action
    // $url = "https://jzh-test.fuiou.com/jzh/BalanceAction.action";//请求的页面地址
    //$url = "https://jzh.fuiou.com/BalanceAction.action";//请求的页面地址
    //POST的参数
    $request_name="BalanceAction.action";
    $param = array('mchnt_txn_ssn'=>$mchnt_txn_ssn,'mchnt_cd'=>$mchnt_cd,'mchnt_txn_dt'=>$mchnt_txn_dt,'cust_no'=>$cust_no,);
    $param['signature']=$signature;

    $result=curlPostdata($param,$request_name);
    function curlPostdata($param,$request_name){
    $url='https://jzh.fuiou.com/BalanceAction.action';
    $postFields = http_build_query($param);
    // $postField2=htmlspecialchars($postFields1);
    // $postFields = html_entity_decode($postField2);
    $postFields=str_replace("amp;", "", $postFields);   //当时手机端请求富友老是报错,后来查询订单号才知道是拼接字符串的时候多出来“amp;”,所以这样解决,而pc端就没有这种问题,把问题附图放在下面
    $ch = curl_init ();
    curl_setopt ( $ch, CURLOPT_POST, 1 );
    curl_setopt ( $ch, CURLOPT_HEADER, 0 );
    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt ( $ch, CURLOPT_URL, $url );
    curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postFields );
    $result = curl_exec ( $ch );
    echo $result;
    curl_close ( $ch );
    return $result;
    }

     


    //获取余额结束

    生活赋予我们一种巨大的和无限高贵的礼品,这就是青春:充满着力量,充满着期待志愿,充满着求知和斗争的志向,充满着希望信心和青春。
  • 相关阅读:
    请问set JAVA_OPTS的各项參数是什么意思?
    微软正式提供Visual Studio 2013正式版下载(附直接链接汇总)
    基础总结篇之中的一个:Activity生命周期
    [Cocos2d-x]Mac下cocos2d-x连接pomeloserver
    window.location.href的使用方法
    springMVC简单实例
    mybatis快速入门
    出现传值问题
    el表达式判断字符串相等
    EL表达式
  • 原文地址:https://www.cnblogs.com/mengcode/p/7132320.html
Copyright © 2011-2022 走看看