$transtype = "0001"; //接口版本号,单笔查询,固定为 20060831,必填 $version = "20060831"; //备注,最长60位,可选 $resv = "memo"; //按次序组合报文信息为待签名串 $plain = $merid . $transdate . $ordid . $transtype; //生成签名值,必填 $chkvalue = sign($plain); if (!$chkvalue) { echo "签名失败!"; exit; } $http = HttpInit(); $post_data = "MerId={$merid}&TransType={$transtype}&OrdId={$ordid}&TransDate={$transdate}&Version={$version}&Resv={$resv}&ChkValue={$chkvalue}"; $output = HttpPost($http, $post_data, REQ_URL_QRY); if ($output) { $output = trim(strip_tags($output)); echo "<h2>查询返回</h2>"; echo htmlspecialchars($output) . "<br/>"; echo "=================================<br/>"; //开始解析数据 $datas = explode("&", $output); $extracted_data = array(); foreach ($datas as $data) { echo "{$data}<br/>"; $name_value = explode('=', $data); if (count($name_value) == 2) { $extracted_data[$name_value[0]] = $name_value[1]; } }
$params = count($argv) >= 2 ? json_decode($argv[1], TRUE) : json_decode(Assign($_REQUEST['data'], '{}'), TRUE); $result = array('code' => '100', 'msg' => MESSAGE_ERROR); ## 統計API調用信息 if (DEBUG == FALSE) { $api_log = array('apicode' => Assign($params['code']), 'uid' => Assign($params['uid'], '0'), 'deviceid' => Assign($params['deviceid']), 'createdat' => 'NOW()', 'ip' => $_SERVER['REMOTE_ADDR'], 'apiver' => API_NAME . '-' . API_VERSION); StorageAdd('hh_api_log', $api_log); } ## 兼容接口編號 $apicodes = array('1', '24', '25', '26', '28', '29', '31', '32', '33', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '49', '50', '54', '55', '60', '62', '94', '95', '96'); ## 加載相對應API接口腳本 $script = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'API' . substr(strval($params['code'] + 1000), 1, 3) . '.php'; if (file_exists($script) == FALSE) { die('Permission denied for the APIs'); } else { if (in_array($params['code'], $apicodes)) { die(HttpPost('http://www.haohaoxiuche.com/api_hhxc4.php', array('data' => JsonEncode($params)))); } else { require_once $script; } } header('Content-Type: text/html;charset=utf-8'); header('Access-Control-Allow-Origin:*'); mysqli_close($mysql); die(JsonEncode($result)); /**************************************** 公共函數 ****************************************/ // 檢測用戶OpenID有效性 function CheckOpenID($loginid, $uid = 0) { if (DEBUG == FALSE and FALSE) { $result = StorageQueryOne('hh_techuser', '*', array('loginid' => $loginid, 'zhuangtai' => 1)); if (is_array($result)) {
function UnitTest($apicode, $request = array()) { $script = ''; $response = ''; if (API_VERSION != 'dev' and API_VERSION != 'test') { $script = sprintf(API_URL, API_NAME, API_VERSION); } else { if (empty($_REQUEST['development']) and count($argv) == 1) { $script = sprintf(API_URL, API_NAME, API_VERSION); } else { if (count($argv) == 1) { $script = sprintf(API_TEST_URL, API_NAME, API_VERSION); } else { $script = join(array(API_ROOT, API_NAME, 'dev', 'index.php'), DIRECTORY_SEPARATOR); } } } $request['code'] = "{$apicode}"; $params = JsonEncode($request); if (strpos($script, 'http') === 0) { $response = HttpPost($script, array('data' => $params)); } else { $response = shell_exec(sprintf("/usr/bin/php %s '%s'", $script, $params)); } echo "Request: "; print_r($request); echo "Response: "; $result = json_decode($response, TRUE); if ($result) { print_r($result); } else { print_r($response); } }
//接口版本号,单笔退款,固定为 20070129,必填 $version = "20070129"; //退款返回地址,退款提交后需经过人工审核处理,并在T+2日后完成,此时我方服务器将POST退款结果到该地址 $returnurl = "{$site_url}/netpayclient_refund_feedback.php"; //按次序组合报文信息为待签名串 $plain = $merid . $transdate . $transtype . $ordid . $refundamount . $priv1; //生成签名值,必填 $chkvalue = sign($plain); if (!$chkvalue) { echo "签名失败!"; exit; } //生产环境提交地址为 ,更换生产密钥后请注意修改 $http = HttpInit(); $post_data = "MerID={$merid}&TransType={$transtype}&OrderId={$ordid}&RefundAmount={$refundamount}&TransDate={$transdate}&Version={$version}&ReturnURL={$returnurl}&Priv1={$priv1}&ChkValue={$chkvalue}"; $output = HttpPost($http, $post_data, REQ_URL_REF); if ($output) { $output = trim(strip_tags($output)); echo "<h2>退款返回</h2>"; echo htmlspecialchars($output) . "<br/>"; echo "=================================<br/>"; //开始解析数据 $datas = explode("&", $output); $extracted_data = array(); foreach ($datas as $data) { echo "{$data}<br/>"; $name_value = explode('=', $data); if (count($name_value) == 2) { $extracted_data[$name_value[0]] = $name_value[1]; } }
$plain = $merId . $version; //进行Base64编码 $data = base64_encode($plain); //生成签名值,必填 $chkvalue = $client_sign->sign($data); if (!$chkvalue) { echo "签名失败!"; exit; } ?> <title>备付金余额查询</title> <h1>备付金余额查询</h1> <?php $http = HttpInit(); $post_data = "merId={$merId}&version={$version}&signFlag={$signFlag}&chkValue={$chkvalue}"; $output = HttpPost($http, $post_data, Balance_URL_QRY); print_r($http); echo '1231'; if ($output) { $output = trim(strip_tags($output)); echo "<h2>查询返回</h2>"; echo htmlspecialchars($output) . "<br/>"; echo "=================================<br/>"; //开始解析数据 $datas = explode("|", $output); foreach ($datas as $data) { echo "{$data}<br/>"; } echo "=================================<br/>"; $dex = strripos($output, "|"); $plain = substr($output, 0, $dex + 1);
//进行Base64编码 $signData = base64_encode($plain); //生成签名值,必填 $chkvalue = $client_sign->sign($signData); if (!$chkvalue) { echo "签名失败!"; exit; } ?> <title>批量退单查询</title> <h1>批量退单查询</h1> <?php if ($fromDate != '' && $toDate != '') { $http = HttpInit(); $post_data = "merId={$merId}&fromDate={$fromDate}&toDate={$toDate}&stat={$stat}&version={$version}&signFlag={$signFlag}&chkValue={$chkvalue}"; $output = HttpPost($http, $post_data, BatchOrder_URL_QRY); if ($output) { $output = trim(strip_tags($output)); echo "<h2>查询返回</h2>"; echo htmlspecialchars($output) . "<br/>"; echo "=================================<br/>"; //开始解析数据 $datas = explode("\r\n", $output); $i = 1; foreach ($datas as $data) { echo "Line = {$i} 返回报文:<br/> " . "{$data}<br/>"; $dex = strripos($data, "|"); $plain = substr($data, 0, $dex + 1); echo "验签明文:<br/>" . $plain . "<br/>"; $plaindata = base64_encode($plain); $chkValue = substr($data, $dex + 1);
//进行Base64编码 $data = base64_encode($plain); //生成签名值,必填 $chkValue = $client_sign->sign($data); if (!$chkValue) { echo "签名失败!"; exit; } ?> <title>单笔查询</title> <h1>单笔查询</h1> <?php if ($merSeqId != '' && $merDate != '') { $http = HttpInit(); $post_data = "merId={$merId}&merDate={$merDate}&merSeqId={$merSeqId}&version={$version}&signFlag={$signFlag}&chkValue={$chkValue}"; $output = HttpPost($http, $post_data, QRY_URL); if ($output) { $output = trim(strip_tags($output)); echo "<h2>查询返回</h2>"; echo htmlspecialchars($output) . "<br/>"; echo "=================================<br/>"; //开始解析数据 $datas = explode("|", $output); foreach ($datas as $data) { echo "{$data}<br/>"; } echo "=================================<br/>"; $dex = strripos($output, "|"); $plain = substr($output, 0, $dex + 1); echo "验签明文:<br/>" . $plain . "<br/>"; $plaindata = base64_encode($plain);
//进行Base64编码 $signData = base64_encode($plain); //生成签名值,必填 $chkvalue = $client_sign->sign($signData); if (!$chkvalue) { echo "签名失败!"; exit; } ?> <title>备付金明细查询</title> <h1>备付金明细查询</h1> <?php if ($fromDate != '' && $toDate != '') { $http = HttpInit(); $post_data = "merId={$merId}&fromDate={$fromDate}&toDate={$toDate}&type={$type}&version={$version}&signFlag={$signFlag}&chkValue={$chkvalue}"; $output = HttpPost($http, $post_data, DepositDetail_URL_QRY); if ($output) { $output = trim(strip_tags($output)); echo "<h2>查询返回</h2>"; echo htmlspecialchars($output) . "<br/>"; echo "=================================<br/>"; //开始解析数据 $datas = explode("\r\n", $output); $extracted_data = array(); foreach ($datas as $data) { echo "{$data}<br/>"; } echo "=================================<br/>"; $dex = strlen($output) - 256; $plain = substr($output, 0, $dex); echo "验签明文:<br/>" . $plain . "<br/>";
/** * 获取信息 * @param [type] $method [description] * @param [type] $param [description] * @return [type] [description] */ function get_data($method, $param, &$use_jd_num) { /** * 指定环境入口地址serverUrl,appKey,appSecretKey,token */ $serverUrl = "http://gw.api.360buy.com/routerjson"; //正式地址 // $serverUrl = "http://gw.api.sandbox.360buy.com/routerjson";//沙箱地址 // $appKey = "463A2AC702BA81B4BE2F68A19BF4E1C3";//xf9 // $appSecretKey = "cf660ee61b644d67873070262ec9fd58";//xf9 // $appKey = "8B9F33567751BC370AB93199892983EE";//2xf9 // $appSecretKey = "c00a719ce26841dea7643008485665ae";//2xf9 // $appKey = "702DC620FA0B096C9043C67CF9470B31";//3xf9 // $appSecretKey = "9a41f7fe457443db843ac956721c5118";//3xf9 // $appKey = "7DDF30C4393B2ADEBCD6BD47E917DB15";//4xf9 // $appSecretKey = "fe73841c2d6148e9a1b46fd312169be5";//4xf9 // $appKey = "1C5B25BDABAA4D91BF23A7930D179618";//5xf9 // $appSecretKey = "56d189becdc1445eaaee1b5e03dd76ad";//5xf9 // $appKey = "C821E534155050EBC1F41C3F5C69333E";//6xf9 // $appSecretKey = "e0265f68e6fd4557819538f33e898882";//6xf9 // $appKey = "7D7C761C5E3E20E15C0DA942438D7550";//7xf9 // $appSecretKey = "63ca8a708ccf460da3f2244e8b5ca362";//7xf9 $appKey = "E8BA95FCD02322AC07F056DD8FF9CBC9"; //8xf9 $appSecretKey = "250d5b233e1e46c7ac04b4977bb6b2f7"; //8xf9 // $appKey = "890E8D245D285B2AE98C635C2A32D31D";//9xf9 // $appSecretKey = "848e4cb06bfd49b2952d6de711ffe572";//9xf9 // $appKey = "CB1161C4EEBB083B54256CCF16A6B6C1";//10 // $appSecretKey = "86712e7207a646a491b8ad02839eff88";//10 // $appKey = "D35197181D2531297FB8A26DB1EA9C45";//11 // $appSecretKey = "3453df0d23854c569232afc28cceb405";//11 // $appKey = "0DC8F3BD553CFA3D0C4DF6E3C6F60588";//12 // $appSecretKey = "76965a6f84914c0fa544158f0f016727";//12 // $appKey = "9A81573A55785F303BEAFB1D23395182";//13 // $appSecretKey = "627dcf9db5674ae9af7604eb25814ad4";//13 // $appKey = "2AF22C294FE6FC922C9D5E82E86B31FD";//14 // $appSecretKey = "7e9186b5f0734b5eaf1f4b815dd92fa5";//14 $token = "f0430d61-c2de-4310-8d71-c59a530a87f1"; /** * 第一步:拼接原串,通过原串获取签名sign */ //拼接原串 $sourceSign = getParam($param, $token, $appKey, $method, $appSecretKey); //获得签名 $sign = getSignByAPI($sourceSign); /** * 第二步:拼接系统参数 */ //拼接token $tokenUrl = isset($token) == false ? "" : "access_token=" . $token; //请求的参数 $data = "app_key=" . $appKey . "&" . "v=2.0&" . $tokenUrl . "&" . "method=" . $method . "&" . "360buy_param_json=" . urlencode($param) . "&" . "sign=" . $sign . "×tamp=" . urlencode(date("Y-m-d H:i:s", time())); /** * 第三步:发送请求,返回的数据即为响应的数据 */ //获取返回信息 $response = HttpPost($serverUrl, $data); echo "use jd api num : " . $use_jd_num++ . "\n"; //json转数组后返回 return json_decode($response, true); }