• 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;
    }

     


    //获取余额结束

    生活赋予我们一种巨大的和无限高贵的礼品,这就是青春:充满着力量,充满着期待志愿,充满着求知和斗争的志向,充满着希望信心和青春。
  • 相关阅读:
    Android开发环境搭建全程演示(jdk+eclip+android sdk)
    mysql UDF接口 网络编程(代码改进版非阻塞,超时重传)
    HTTP_POST———使用mysql_udf与curl库完成http_post通信模块(mysql_udf,multi_curl,http,post)
    Linux自动更新时间
    CentOS下设置Mysql的root密码
    CentOS yum安装LAMP环境
    Nagios远程监控软件的安装与配置详解
    Android开发之旅:环境搭建及HelloWorld
    CentOS 6.3安装配置LAMP服务器(Apache+PHP5+MySQL)
    c#,winform,show,showdialog,子窗体,父窗体,传值,输入正确
  • 原文地址:https://www.cnblogs.com/mengcode/p/7132320.html
Copyright © 2020-2023  润新知