返回 登录
0

通过PHP调用天市数据的水电煤缴费接口

前置条件
在开始前,请作如下准备
1.学会用PHP输出“Hello World”
2.去 天市数据 申请火车查询专用的KEY

操作步骤
1.配置好PHP开发环境
2.新建一个index.php文件,并输入以下内容:

<?php

require_once 'curl.func.php';

$appkey = 'your_appkey_here';//你的appkey
$productid = 2512;//商品ID
$account = '6029023500';//充值账号
$amount = 200;//充值金额
$outorderno = '77888855888';//商家订单号 可选 
$appsecret = 'sssssssssss';//你的appsecret
$queryarr = array('account'=>$account,'amount'=>$amount,'productid'=>$productid,'outorderno'=>$outorderno);
$sign = makeSign($queryarr, $appsecret);
$url = "http://apis.tiisi.com/waterelectricrecharge/recharge?appkey=$appkey&productid=$productid&account=$account&amount=$amount&sign=$sign";
$result = curlOpen($url);
$jsonarr = json_decode($result, true);
//exit(var_dump($jsonarr));

if($jsonarr['status'] != 0)
{
    echo $jsonarr['msg'];
    exit();
}

echo $result['productid'].' '.$result['account'].' '.$result['amount'].' '.$result['outorderno'].' '.$result['orderno'].' '.$result['rechargestatus'];

function makeSign($queryarr, $appsecret)
{
    ksort($queryarr, SORT_STRING);
    $str = implode($queryarr);
    $str .= $appsecret;
    //exit($str);
    $str = md5($str);

    return $str;
}

3.打开浏览器,访问http://localhost/index.php,正常情况下你应该看到类似下面的内容:

{
    "status": "0",
    "msg": "ok",
    "result": {
        "productid": "2512",
        "account": "6029023500",        
        "amount": "200",
        "outorderno": "",
        "orderno": "201605231550666084322",
        "rechargestatus": "0"
    }
}
评论