添加后台代理代码
This commit is contained in:
17
codes/agent/game/api/payment/ipay/.project
Normal file
17
codes/agent/game/api/payment/ipay/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>IapppayCpSyncForPHP_20150901</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>net.sourceforge.phpeclipse.parserbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>net.sourceforge.phpeclipse.phpnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
33
codes/agent/game/api/payment/ipay/CheckLogin.php
Normal file
33
codes/agent/game/api/payment/ipay/CheckLogin.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
/*
|
||||
* Created on 2015-8-31
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - PHPeclipse - PHP - Code Templates
|
||||
*/
|
||||
require_once ("config.php");
|
||||
require_once ("base.php");
|
||||
/*
|
||||
* 在客户端调用登陆接口,得到返回 logintoken 客户端把 logintoken 传给 服务端
|
||||
* 服务端组装验证令牌的请求参数:transdata={"appid":"123","logintoken":"3213213"}&sign=xxxxxx&signtype=RSA
|
||||
* 请求地址:以文档给出的为准
|
||||
*/
|
||||
function ReqData() {
|
||||
global $tokenCheckUrl, $appkey, $platpkey;
|
||||
//数据现组装成:{"appid":"12313","logintoken":"aewrasera98seuta98e"}
|
||||
$contentdata["appid"]="3003686553";
|
||||
$contentdata["logintoken"]="55e37ac2c0dc98972475d640";//这个需要调登录接口时时获取。有效期10min
|
||||
//组装请求报文 格式:$reqData="transdata={"appid":"123","logintoken":"3213213"}&sign=xxxxxx&signtype=RSA"
|
||||
$reqData = composeReq($contentdata, $appkey);
|
||||
echo "reqData:$reqData\n";
|
||||
HttpPost($tokenCheckUrl,$reqData);
|
||||
|
||||
}
|
||||
|
||||
ReqData();
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
39
codes/agent/game/api/payment/ipay/ContractAuthentication.php
Normal file
39
codes/agent/game/api/payment/ipay/ContractAuthentication.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
/*
|
||||
* Created on 2015-8-31
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - PHPeclipse - PHP - Code Templates
|
||||
*/
|
||||
require_once ("config.php");
|
||||
require_once ("base.php");
|
||||
|
||||
/*
|
||||
* 此demo 代码 使用于 用户契约鉴权。
|
||||
* 请求地址见文档
|
||||
* 请求方式:post
|
||||
* 流程:cp服务端组装请求参数并对参数签名,以post方式提交请求并获得响应数据,处理得到的响应数据,调用验签函数对数据验签。
|
||||
* 请求参数及请求参数格式:transdata={"appid":"500000185","appuserid":"A100003A832D40","waresid":1}&sign=N85bxusvUozqF3iwfAq3Ts3UeyZn8mKi5BVe+H+Vg1nrcE06AhHt7IrJLO3I5njZSF4g5CbLMLiTJiXCmNsH/t35gU3bmIKFPKiw7g3aq0hMofyhgsCLXSWEOrSIa7W6mLzPcEhUkjdX9XxsASbsILHTrJwZYYG7d9PTyhqSmoA=&signtype=RSA
|
||||
* 以下实现 各项请求参数 处理代码:
|
||||
*
|
||||
* */
|
||||
|
||||
function ReqData($appid,$appuserid,$waresid){
|
||||
global $ContractAuthenticationUrl, $appkey, $platpkey;
|
||||
//组装参数json格式:
|
||||
$contentdata["appid"]="3002495803";
|
||||
$contentdata["appuserid"]="55e37ac2c0dc98972475d640";
|
||||
$contentdata["waresid"]=1;
|
||||
//调用函数组装json格式,并且对数据进行签名,最终组装请求参数 如::transdata={"appid":"500000185","appuserid":"A100003A832D40","waresid":4}&sign=N85bxusvUozqF3iwfAq3Ts3UeyZn8mKi5BVe+H+Vg1nrcE06AhHt7IrJLO3I5njZSF4g5CbLMLiTJiXCmNsH/t35gU3bmIKFPKiw7g3aq0hMofyhgsCLXSWEOrSIa7W6mLzPcEhUkjdX9XxsASbsILHTrJwZYYG7d9PTyhqSmoA=&signtype=RSA
|
||||
$reqData = composeReq($contentdata, $appkey);
|
||||
echo "reqData:$reqData\n";
|
||||
HttpPost($ContractAuthenticationUrl,$reqData);
|
||||
|
||||
}
|
||||
|
||||
|
||||
ReqData();
|
||||
|
||||
|
||||
?>
|
||||
37
codes/agent/game/api/payment/ipay/ContractCancel.php
Normal file
37
codes/agent/game/api/payment/ipay/ContractCancel.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
/*
|
||||
* Created on 2015-8-31
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - PHPeclipse - PHP - Code Templates
|
||||
*/
|
||||
require_once ("config.php");
|
||||
require_once ("base.php");
|
||||
/*
|
||||
* 此demo 代码 使用于 用户可以对已经完成购买的契约进行退订,退订时会将契约置为退订状态,在该状态下用户仍然可以使用该商品,直到契约失效,但是不再进行自动续费。
|
||||
* 请求地址见文档
|
||||
* 请求方式:post
|
||||
* 流程:cp服务端组装请求参数并对参数签名,以post方式提交请求并获得响应数据,处理得到的响应数据,调用验签函数对数据验签。
|
||||
* 请求参数及请求参数格式:transdata={"appid":"500000185","appuserid":"A100003A832D40","waresid":1}&sign=VvT9gHqGjwuhj07/lbcErBo6b23tX1Z5f/aiBItCw5YlFZb6MQpg/NLc9SCA6qc+S6Pw+Jqe87QiiWpXhPf1fEIclLdu5vWmbFMvA4VMW+Il+6oTJFuJItjfIfhGhljEIrgqXO5ZrNs8mrbKBkJHjUtHv1jRFzFtCQZeMgwZr3U=&signtype=RSA
|
||||
* 以下实现 各项请求参数 处理代码:
|
||||
*
|
||||
* */
|
||||
function ReqData() {
|
||||
global $subcancel, $appkey, $platpkey;
|
||||
//数据现组装成:{"appid":"12313","appuserid":"aewrasera98seuta98e"}
|
||||
$contentdata["appid"]="3002495803";
|
||||
$contentdata["appuserid"]="55e37ac2c0dc98972475d640";
|
||||
$contentdata["waresid"]=1;
|
||||
//组装请求报文 格式:$reqData="transdata={"appid":"500000185","appuserid":"A100003A832D40","waresid":1}&sign=xxxxxx&signtype=RSA"
|
||||
$reqData = composeReq($contentdata, $appkey);
|
||||
echo "reqData:$reqData\n";
|
||||
HttpPost($subcancel,$reqData);
|
||||
}
|
||||
|
||||
ReqData();
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
38
codes/agent/game/api/payment/ipay/QueryContract.php
Normal file
38
codes/agent/game/api/payment/ipay/QueryContract.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
/*
|
||||
* Created on 2015-8-31
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - PHPeclipse - PHP - Code Templates
|
||||
*/
|
||||
require_once ("config.php");
|
||||
require_once ("base.php");
|
||||
/*
|
||||
* 此demo 代码 使用于 cp 通过主动查询方式 获取商品契约。
|
||||
* 请求地址见文档
|
||||
* 请求方式:post
|
||||
* 流程:cp服务端组装请求参数并对参数签名,以post方式提交请求并获得响应数据,处理得到的响应数据,调用验签函数对数据验签。
|
||||
* 请求参数及请求参数格式:transdata={"appid":"500000185","appuserid":"A100003A832D40"}&sign=VvT9gHqGjwuhj07/lbcErBo6b23tX1Z5f/aiBItCw5YlFZb6MQpg/NLc9SCA6qc+S6Pw+Jqe87QiiWpXhPf1fEIclLdu5vWmbFMvA4VMW+Il+6oTJFuJItjfIfhGhljEIrgqXO5ZrNs8mrbKBkJHjUtHv1jRFzFtCQZeMgwZr3U=&signtype=RSA
|
||||
* 以下实现 各项请求参数 处理代码:
|
||||
*
|
||||
* */
|
||||
|
||||
function ReqData() {
|
||||
global $querysubsUrl, $appkey, $platpkey;
|
||||
//数据现组装成:{"appid":"12313","logintoken":"aewrasera98seuta98e"}
|
||||
$contentdata["appid"]="3002495803";
|
||||
$contentdata["appuserid"]="55e37ac2c0dc98972475d640";
|
||||
//组装请求报文 格式:$reqData="transdata={"appid":"123","appuserid":"3213213"}&sign=xxxxxx&signtype=RSA"
|
||||
$reqData = composeReq($contentdata, $appkey);
|
||||
echo "reqData:$reqData\n";
|
||||
HttpPost($querysubsUrl,$reqData);
|
||||
|
||||
}
|
||||
|
||||
ReqData();
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
/*
|
||||
* Created on 2015-8-28
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - PHPeclipse - PHP - Code Templates
|
||||
*/
|
||||
require_once ("config.php");
|
||||
require_once ("base.php");
|
||||
/**
|
||||
* 类名:demo 功能 服务器端签名与验签Demo 版本:1.0 日期:2014-06-26 '说明:
|
||||
* '以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
* '该代码仅供学习和研究爱贝云计费接口使用,只是提供一个参考。
|
||||
*/
|
||||
|
||||
/*
|
||||
* 此demo 代码 使用于 cp 通过主动查询方式 获取同步数据。
|
||||
* 请求地址见文档
|
||||
* 请求方式:post
|
||||
* 流程:cp服务端组装请求参数并对参数签名,以post方式提交请求并获得响应数据,处理得到的响应数据,调用验签函数对数据验签。
|
||||
* 请求参数及请求参数格式:transdata={"appid":"123456","cporderid":"3213213"}&sign=xxxxxx&signtype=RSA
|
||||
* 注意:只有在客户端支付成功的订单,主动查询才会有交易数据。
|
||||
* 以下实现 各项请求参数 处理代码:
|
||||
*
|
||||
* */
|
||||
function ReqData() {
|
||||
global $queryResultUrl, $appkey, $platpkey;
|
||||
//数据现组装成:{"appid":"12313","logintoken":"aewrasera98seuta98e"}
|
||||
$contentdata["appid"]="3002495803";
|
||||
$contentdata["cporderid"]="55e37ac2c0dc98972475d640";
|
||||
//组装请求报文 格式:$reqData="transdata={"appid":"123","logintoken":"3213213"}&sign=xxxxxx&signtype=RSA"
|
||||
$reqData = composeReq($contentdata, $appkey);
|
||||
echo "reqData:$reqData\n";
|
||||
HttpPost($queryResultUrl,$reqData);
|
||||
|
||||
}
|
||||
|
||||
ReqData();
|
||||
?>
|
||||
19
codes/agent/game/api/payment/ipay/Test.php
Normal file
19
codes/agent/game/api/payment/ipay/Test.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
/*
|
||||
* Created on 2015-9-1
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - PHPeclipse - PHP - Code Templates
|
||||
*/
|
||||
|
||||
function test() {
|
||||
|
||||
echo "充值成功";
|
||||
|
||||
|
||||
}
|
||||
test();
|
||||
|
||||
|
||||
?>
|
||||
60
codes/agent/game/api/payment/ipay/TradingResultsNotice.php
Normal file
60
codes/agent/game/api/payment/ipay/TradingResultsNotice.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
/*
|
||||
* Created on 2015-9-1
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - PHPeclipse - PHP - Code Templates
|
||||
*/
|
||||
require_once("base.php");
|
||||
require_once("config.php");
|
||||
function testResult()
|
||||
{
|
||||
global $queryResultUrl, $platpkey;
|
||||
$string = $_POST;//接收post请求数据
|
||||
$cporderid = null;
|
||||
if ($string == null) {
|
||||
echo "请使用post方式提交数据";
|
||||
} else {
|
||||
$transdata = $string['transdata'];
|
||||
echo "$transdata\n";
|
||||
if (stripos("%22", $transdata)) { //判断接收到的数据是否做过 Urldecode处理,如果没有处理则对数据进行Urldecode处理
|
||||
$string = array_map('urldecode', $string);
|
||||
}
|
||||
$respData = 'transdata=' . $string['transdata'] . '&sign=' . $string['sign'] . '&signtype=' . $string['signtype'];//把数据组装成验签函数要求的参数格式
|
||||
// 验签函数parseResp() 中 只接受明文数据。数据如:transdata={"appid":"3003686553","appuserid":"10123059","cporderid":"1234qwedfq2as123sdf3f1231234r","cpprivate":"11qwe123r23q232111","currency":"RMB","feetype":0,"money":0.12,"paytype":403,"result":0,"transid":"32011601231456558678","transtime":"2016-01-23 14:57:15","transtype":0,"waresid":1}&sign=jeSp7L6GtZaO/KiP5XSA4vvq5yxBpq4PFqXyEoktkPqkE5b8jS7aeHlgV5zDLIeyqfVJKKuypNUdrpMLbSQhC8G4pDwdpTs/GTbDw/stxFXBGgrt9zugWRcpL56k9XEXM5ao95fTu9PO8jMNfIV9mMMyTRLT3lCAJGrKL17xXv4=&signtype=RSA
|
||||
echo "进入了2" . $respData;
|
||||
if (!parseResp($respData, $platpkey, $respJson)) {
|
||||
//验签失败
|
||||
echo 'failed' . "\n";
|
||||
} else {
|
||||
//验签成功
|
||||
echo 'success' . "\n";
|
||||
//以下是 验签通过之后 对数据的解析。
|
||||
$transdata = $string['transdata'];
|
||||
$arr = json_decode($transdata);
|
||||
$appid = $arr->appid;
|
||||
$appuserid = $arr->appuserid;
|
||||
$cporderid = $arr->cporderid;
|
||||
$cpprivate = $arr->cpprivate;
|
||||
$money = $arr->paytype;
|
||||
$result = $arr->result;
|
||||
$transid = $arr->transid;
|
||||
$transtime = $arr->transtime;
|
||||
$waresid = $arr->waresid;
|
||||
echo "$appid\n";
|
||||
echo "$appuserid\n";
|
||||
echo "$cporderid\n";
|
||||
echo "$cpprivate\n";
|
||||
echo "$money\n";
|
||||
echo "$result\n";
|
||||
echo "$transid\n";
|
||||
echo "$transtime\n";
|
||||
echo "$waresid\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
testResult();
|
||||
?>
|
||||
200
codes/agent/game/api/payment/ipay/base.php
Normal file
200
codes/agent/game/api/payment/ipay/base.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
/**
|
||||
*功能:爱贝云计费接口公用函数
|
||||
*详细:该页面是请求、通知返回两个文件所调用的公用函数核心处理文件
|
||||
*版本:1.0
|
||||
*修改日期:2014-06-26
|
||||
* '说明:
|
||||
* '以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
* '该代码仅供学习和研究爱贝云计费接口使用,只是提供一个参考。
|
||||
*/
|
||||
|
||||
/**格式化公钥
|
||||
* $pubKey PKCS#1格式的公钥串
|
||||
* return pem格式公钥, 可以保存为.pem文件
|
||||
*/
|
||||
function formatPubKey($pubKey)
|
||||
{
|
||||
$fKey = "-----BEGIN PUBLIC KEY-----\n";
|
||||
$len = strlen($pubKey);
|
||||
for ($i = 0; $i < $len;) {
|
||||
$fKey = $fKey . substr($pubKey, $i, 64) . "\n";
|
||||
$i += 64;
|
||||
}
|
||||
$fKey .= "-----END PUBLIC KEY-----";
|
||||
return $fKey;
|
||||
}
|
||||
|
||||
|
||||
/**格式化公钥
|
||||
* $priKey PKCS#1格式的私钥串
|
||||
* return pem格式私钥, 可以保存为.pem文件
|
||||
*/
|
||||
function formatPriKey($priKey)
|
||||
{
|
||||
$fKey = "-----BEGIN RSA PRIVATE KEY-----\n";
|
||||
$len = strlen($priKey);
|
||||
for ($i = 0; $i < $len;) {
|
||||
$fKey = $fKey . substr($priKey, $i, 64) . "\n";
|
||||
$i += 64;
|
||||
}
|
||||
$fKey .= "-----END RSA PRIVATE KEY-----";
|
||||
return $fKey;
|
||||
}
|
||||
|
||||
/**RSA签名
|
||||
* $data待签名数据
|
||||
* $priKey商户私钥
|
||||
* 签名用商户私钥
|
||||
* 使用MD5摘要算法
|
||||
* 最后的签名,需要用base64编码
|
||||
* return Sign签名
|
||||
*/
|
||||
function sign($data, $priKey)
|
||||
{
|
||||
//转换为openssl密钥
|
||||
$res = openssl_get_privatekey($priKey);
|
||||
|
||||
//调用openssl内置签名方法,生成签名$sign
|
||||
openssl_sign($data, $sign, $res, OPENSSL_ALGO_MD5);
|
||||
|
||||
//释放资源
|
||||
openssl_free_key($res);
|
||||
|
||||
//base64编码
|
||||
$sign = base64_encode($sign);
|
||||
return $sign;
|
||||
}
|
||||
|
||||
/**RSA验签
|
||||
* $data待签名数据
|
||||
* $sign需要验签的签名
|
||||
* $pubKey爱贝公钥
|
||||
* 验签用爱贝公钥,摘要算法为MD5
|
||||
* return 验签是否通过 bool值
|
||||
*/
|
||||
function verify($data, $sign, $pubKey)
|
||||
{
|
||||
//转换为openssl格式密钥
|
||||
$res = openssl_get_publickey($pubKey);
|
||||
|
||||
//调用openssl内置方法验签,返回bool值
|
||||
$result = (bool)openssl_verify($data, base64_decode($sign), $res, OPENSSL_ALGO_MD5);
|
||||
|
||||
//释放资源
|
||||
openssl_free_key($res);
|
||||
|
||||
//返回资源是否成功
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析response报文
|
||||
* $content 收到的response报文
|
||||
* $pkey 爱贝平台公钥,用于验签
|
||||
* $respJson 返回解析后的json报文
|
||||
* return 解析成功TRUE,失败FALSE
|
||||
*/
|
||||
function parseResp($content, $pkey, &$respJson)
|
||||
{
|
||||
$arr = array_map(create_function('$v', 'return explode("=", $v);'), explode('&', $content));
|
||||
foreach ($arr as $value) {
|
||||
$resp[($value[0])] = $value[1];
|
||||
}
|
||||
|
||||
//解析transdata
|
||||
if (array_key_exists("transdata", $resp)) {
|
||||
$respJson = json_decode($resp["transdata"]);
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//验证签名,失败应答报文没有sign,跳过验签
|
||||
if (array_key_exists("sign", $resp)) {
|
||||
//校验签名
|
||||
$pkey = formatPubKey($pkey);
|
||||
return verify($resp["transdata"], $resp["sign"], $pkey);
|
||||
} else if (array_key_exists("errmsg", $respJson)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* curl方式发送post报文
|
||||
* $remoteServer 请求地址
|
||||
* $postData post报文内容
|
||||
* $userAgent用户属性
|
||||
* return 返回报文
|
||||
*/
|
||||
function request_by_curl($remoteServer, $postData, $userAgent)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $remoteServer);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
|
||||
$data = urldecode(curl_exec($ch));
|
||||
curl_close($ch);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 组装request报文
|
||||
* $reqJson 需要组装的json报文
|
||||
* $vkey cp私钥,格式化之前的私钥
|
||||
* return 返回组装后的报文
|
||||
*/
|
||||
function composeReq($reqJson, $vkey)
|
||||
{
|
||||
//获取待签名字符串
|
||||
$content = json_encode($reqJson);
|
||||
//格式化key,建议将格式化后的key保存,直接调用
|
||||
$vkey = formatPriKey($vkey);
|
||||
|
||||
//生成签名
|
||||
$sign = sign($content, $vkey);
|
||||
|
||||
//组装请求报文,目前签名方式只支持RSA这一种
|
||||
$reqData = "transdata=" . urlencode($content) . "&sign=" . urlencode($sign) . "&signtype=RSA";
|
||||
|
||||
return $reqData;
|
||||
}
|
||||
|
||||
//H5请求报文拼接
|
||||
function h5composeReq($reqJson, $vkey)
|
||||
{
|
||||
//获取待签名字符串
|
||||
$content = json_encode($reqJson);
|
||||
//格式化key,建议将格式化后的key保存,直接调用
|
||||
$vkey = formatPriKey($vkey);
|
||||
|
||||
//生成签名
|
||||
$sign = sign($content, $vkey);
|
||||
|
||||
//组装请求报文,目前签名方式只支持RSA这一种
|
||||
$reqData = "data=" . urlencode($content) . "&sign=" . urlencode($sign) . "&sign_type=RSA";
|
||||
|
||||
return $reqData;
|
||||
}
|
||||
|
||||
|
||||
//发送post请求 ,并得到响应数据 和对数据进行验签
|
||||
function HttpPost($Url, $reqData)
|
||||
{
|
||||
global $cpvkey, $platpkey;
|
||||
$respData = request_by_curl($Url, $reqData, " demo ");
|
||||
if (!parseResp($respData, $platpkey, $notifyJson)) {
|
||||
echo "fail";
|
||||
}
|
||||
echo "TEST respData:$respData\n";
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
44
codes/agent/game/api/payment/ipay/config.php
Normal file
44
codes/agent/game/api/payment/ipay/config.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
/**
|
||||
*功能:配置文件
|
||||
*版本:1.0
|
||||
*修改日期:2014-06-26
|
||||
'说明:
|
||||
'以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
'该代码仅供学习和研究爱贝云计费接口使用,只是提供一个参考。
|
||||
*/
|
||||
|
||||
//爱贝商户后台接入url
|
||||
// $coolyunCpUrl="http://pay.coolyun.com:6988";
|
||||
$iapppayCpUrl="http://ipay.iapppay.com:9999";
|
||||
//登录令牌认证接口 url
|
||||
$tokenCheckUrl=$iapppayCpUrl . "/openid/openidcheck";
|
||||
|
||||
//下单接口 url
|
||||
// $orderUrl=$coolyunCpUrl . "/payapi/order";
|
||||
$orderUrl=$iapppayCpUrl . "/payapi/order";
|
||||
|
||||
//支付结果查询接口 url
|
||||
$queryResultUrl=$iapppayCpUrl ."/payapi/queryresult";
|
||||
|
||||
//契约查询接口url
|
||||
$querysubsUrl=$iapppayCpUrl."/payapi/subsquery";
|
||||
|
||||
//契约鉴权接口Url
|
||||
$ContractAuthenticationUrl=$iapppayCpUrl."/payapi/subsauth";
|
||||
|
||||
//取消契约接口Url
|
||||
$subcancel=$iapppayCpUrl."/payapi/subcancel";
|
||||
//H5和PC跳转版支付接口Url
|
||||
$h5url="https://web.iapppay.com/h5/gateway?";
|
||||
$pcurl="https://web.iapppay.com/pc/gateway?";
|
||||
|
||||
//应用编号
|
||||
$appid="3002495803";
|
||||
//应用私钥
|
||||
$appkey="MIICXgIBAAKBgQDZjpotEmPKwRPKeqb6kqLgmiJkmUQ6EgMAlHBLCAdykb8mAKNWPFs+uyyknOAg+kqQzS9oEoF1P2YYDzYLVQeU4x2c9PtLPMxhXOqdiS6tdJ7RBa2SS4z0WaPmjGAds8qvVnec8Kp5/UXpIDXHRfJ7vNCwNB5O1BEJO/uIRMNIOwIDAQABAoGBAM/HCOpo+NPIyN0FfPotF8/IhXZshqOrViC0o/aU6X/7QILL8zNGG6Ly4nUouknkoVhgDpmnqupOrXPm+yehgsVljoeYRDVEmoyPvFNm+lbv5iDsnHlOohkyEdIO8tMYX7FT269YjWd7PGV1cnHqYUUAq0ncxbu2/RbPbXXsWcAJAkEA83tyOnvKMm46wEaLYXbUzS2iWCv+X0/4h5IKU9q9D2kYhApGaPIOWKf7qtLigkwvSwZ6ZU4kPKcmM817WR64vwJBAOS98iTBD6tYMe6U0Y5E1rO/sQQrIpMwJ2Y6PJQ/uU8z6rXsbEztUR/pbEExkf2a0xCByRxPEwrIRgzBat2Q84UCQHvAvLhY/tZPDHF56ZHqMhLvJNqn0axkGy/c3H7uaLWSdzF1f4ALt5r8FoAmm5YaXtdFPaSL6QMi+dnOkOklIkUCQQCFt0AhGjb1vCXcSWTDHRzBkRKC1FBu6JxvlyWoqCPE2B2h4aZhxe1BkWu2JKsqLGKr6KLPCK6iA/dnJ344La8dAkEA71Mz9WB4fhhU3e284lM1Y6ybS+F5a04racip9NbRAp9bnaDXDBO/EeFM4JZtb48IgnIJ0hfe09y+MDFgw4tgFA==";
|
||||
//平台公钥
|
||||
$platpkey="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDoEQasj75Yi/MWc0ZF0+ZiBmguwSegyr5Z+N5A93VXG7SSA4OSb/eaH5FgCsW25cGxRwfpwl9jamiG4R/2vM72cQFQX5lEK0JkcHd/gxhhGFwGg7snFJpYCxYCflN0WHxrR47rijC7ipzRp+Noq50AMCF79AMaPIRSTCy9gLPpwQIDAQAB";
|
||||
|
||||
?>
|
||||
11
codes/agent/game/api/payment/ipay/index.php
Normal file
11
codes/agent/game/api/payment/ipay/index.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
/*
|
||||
* Created on 2015-8-28
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - PHPeclipse - PHP - Code Templates
|
||||
*/
|
||||
print "Hello World";
|
||||
?>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
MIICXQIBAAKBgQCi4cy1Xqt8aOPLANjeY2jFPHMNJP0PNns9X662Oye8I4ApOlLC16b30aRBaKpCwIiWlbREBsVsmIEK8n50wc+49CrHXV6P8btA0fKvd/EDmRP8AdHk6F9ze/iwHQM2+Yj0BqsWgUCwOwKdIWtEQqPqavH7/lPdxaJXri3zl6rMXwIDAQABAoGAI+GD++xH8JcWnzCnlY3mlZR0b8/XI1PIIEQEs8YiQbK8V9iuRJfHA06eVX5eC2hobmu6E0Y+lWae/q9epg/P1z7MdFUEwdW2OoDorl7Yf4xtLe2t1LcIZ+9Zvx/49mPNVpVmNEzR73glH5jMQ2tvvGHe3EOn4xkxZFPW/32IuZkCQQDo0kW/s6V7z7JXTqrWCFxo9KbQCKmZNRFKEVTeoUrowrGMrhPWabaMbN5NbvfqVn8fbdt0VcMptOmWPTSlIIbNAkEAsxkKVzK/SsbLOim/4BSNEdu7Nd5lnue6jxMO0qPYFeLa2qaAEbM9YdRTtYqzqHwX8Vx5uRGmMhfIeHN6ywdn2wJBAKXxEWOkcIOBstRFrr/kr7DjB25pbjBTwaHwHnSbs5+Y/SGPBXaiXElUY1H/kNZGlk7ZZzxQ0EyOtJqvvzEesNUCQF6+yneiwwvd6rkUSQtUE+T0py8yPfQ4hrsVy+um/bNmVX0CRBIZDknot3f8rlpde5UV5NcA/TjW2BjQjo9Fla0CQQDUqVtXDDt/10s/8mWDKkZIVwDdsYHBC1E+FEw2CQMB/yOT4ve/cmPzbH26ysbqnZoaZelbetwLVe5avYeL0Nh5
|
||||
@@ -0,0 +1 @@
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCIouv++6h+CL/kGDxldXMqb92a3/tszmPzGZ4DkwZhNAkOxLuOTWkYaw5+TGktxnNsjU6YJvC88vH3pYsnmHvCheJnEmj3GNamjig5c7QrzeCgBG974SbIrF7iY/tsdE6YQPfw+Q0oVf+sfFk61wPToQPcQgsJw7tYQrFC+jqe9QIDAQAB
|
||||
16
codes/agent/game/api/payment/ipay/testdemo.php
Normal file
16
codes/agent/game/api/payment/ipay/testdemo.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
|
||||
require_once ("base.php");
|
||||
$respData="transdata={\"transid\":\"32441611021004347926\"}&sign=DxJ5Cw/GTLzT4oEOtzm2bE0Hjb1HPRmXT+OVJj5TRBqC+Zrwdgt7yCW8cbd2IsERqSTlVqQqAx5Bc/ztO6hQVBWZTl7tPZ4jQKs3JOT7r8mcJL6FNCcfItDNZWprcmrTjDZcwsW9+pX+TkP07ouolOg+/sLDC4OE7vu2BURb2mg=&signtype=RSA";
|
||||
$platpkey="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCWAsHq1iezR1zZzGlmXTX0o88hpuOMWUnCO2iEBHSHVB+WuizLmps89Kz90XFHzqZoYtJ0U1aFSYlcboQZQfp/CelToDCrbXyAu43yVpvKIAkZVEpTPvc61HmhyHT4AnbPZ3H6DmS8ljAb8F/jtihZCdvi4JWWY8eOeRuvz5hwAQIDAQAB";
|
||||
if(!parseResp($respData, $platpkey, $respJson)) {
|
||||
echo "failed";
|
||||
}else{
|
||||
echo "success";
|
||||
echo "服务端下单完成,trasnid:<br/>";
|
||||
print_r($respJson);
|
||||
// 下单成功之后获取 transid
|
||||
$transid=$respJson->transid;
|
||||
}
|
||||
?>
|
||||
86
codes/agent/game/api/payment/ipay/trade.php
Normal file
86
codes/agent/game/api/payment/ipay/trade.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
/**
|
||||
*类名:trade.php
|
||||
*功能 服务器端创建交易Demo
|
||||
*版本:1.0
|
||||
*日期:2014-06-26
|
||||
* '说明:
|
||||
* '以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
* '该代码仅供学习和研究爱贝云计费接口使用,只是提供一个参考。
|
||||
*/
|
||||
require_once("config.php");
|
||||
require_once("base.php");
|
||||
|
||||
|
||||
//此为下单函数。使用时请把下列参数按要求更换成你们自己的数据。另外也需要更换config.php 中的公钥和私钥
|
||||
function testOrder()
|
||||
{
|
||||
global $orderUrl, $appkey, $platpkey, $transid, $appid;
|
||||
//下单接口
|
||||
$orderReq['appid'] = "$appid";
|
||||
$orderReq['waresid'] = 1;
|
||||
$orderReq['cporderid'] = "123412zxcvzasdfqwerasdghj"; //确保该参数每次 都不一样。否则下单会出问题。
|
||||
echo "microtime()";
|
||||
$orderReq['price'] = 0.01; //单位:元
|
||||
$orderReq['currency'] = 'RMB';
|
||||
$orderReq['appuserid'] = '10123059';
|
||||
$orderReq['cpprivateinfo'] = '11qwe123r23q232111';
|
||||
$orderReq['notifyurl'] = 'http://58.250.160.241:8888/IapppayCpSyncForPHPDemo/TradingResultsNotice.php';
|
||||
//组装请求报文 对数据签名
|
||||
$reqData = composeReq($orderReq, $appkey);
|
||||
echo "$reqData";
|
||||
//发送到爱贝服务后台请求下单
|
||||
$respData = request_by_curl($orderUrl, $reqData, 'order test');
|
||||
echo "respData:$respData\n";
|
||||
|
||||
//验签数据并且解析返回报文
|
||||
if (!parseResp($respData, $platpkey, $respJson)) {
|
||||
echo "failed";
|
||||
} else {
|
||||
echo "success";
|
||||
echo "服务端下单完成,trasnid:<br/>";
|
||||
print_r($respJson);
|
||||
// 下单成功之后获取 transid
|
||||
$transid = $respJson->transid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//此为H5 和PC 版本调收银台时需要的参数组装函数 特别提醒的是 下面的函数中有 $h5url 和$pcurl 两个url地址。 只需要更换这两个地址就可以 调出 H5 收银台和PC版本收银台。
|
||||
function H5orPCpay()
|
||||
{
|
||||
global $h5url, $pcurl, $appkey, $platpkey, $transid, $appid;//得到transid 再次组装数据并签名。
|
||||
echo "开始组装号调用支付接口的参数";
|
||||
//下单接口
|
||||
$orderReq['tid'] = $transid;
|
||||
|
||||
$orderReq['app'] = $appid; // appid
|
||||
|
||||
$orderReq['url_r'] = 'http://www.baidu.com'; //支付成功后支付回调URL地址
|
||||
|
||||
$orderReq['url_h'] = 'http://www.baidu.com'; //返回商户URL地址
|
||||
//组装请求报文 对数据签名
|
||||
$reqData = h5composeReq($orderReq, $appkey);
|
||||
|
||||
echo "参数组装完成:请用浏览器访问该链接:$h5url$reqData\n";//这里组装的最终数据 就可以用浏览器访问调出收银台。
|
||||
echo "<script language=\"javascript\">";
|
||||
echo "location.href=\"$h5url$reqData\"";//我们的常连接版本 有PC 版本 和移动版本。 根据使用的环境不同请更换相应的URL:$h5url,$pcurl.
|
||||
echo "</script>";
|
||||
}
|
||||
|
||||
//在使用H5 Iframe版本时 生成签名数据 次函数只适用于H5 Iframe版本支付。
|
||||
function H5IframeSign($transid, $redirecturl, $cpurl, $appkey)
|
||||
{
|
||||
$content = trim($transid) . '' . trim($redirecturl) . '' . trim($cpurl);//拼接$transid $redirecturl $cpurl
|
||||
$appkey = formatPriKey($appkey);
|
||||
$sign = sign($content, $appkey);
|
||||
return $sign;
|
||||
}
|
||||
|
||||
|
||||
testOrder();
|
||||
H5orPCpay();
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user