forked from terrancy/PaySDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathucSDK.php
135 lines (118 loc) · 5.77 KB
/
ucSDK.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
class ucSDK{
private $resultSuccess = 0;
private $resultFailed = 1;
function __construct($idApp="",$keyApi=""){
if(!empty($idApp)){
$this->_idApp = $idApp;
}
if(!empty($keyApi)){
$this->_keyApi = $keyApi;
}
}
function getUCBaseInit(){
require_once dirname(__FILE__).'/uc/service/SDKServerService.php';
require_once dirname(__FILE__).'/uc/model/SDKException.php';
}
function getUCPayInit(){
require_once dirname(__FILE__).'/uc/util/ConfigHelper.php';
require_once dirname(__FILE__).'/uc/util/LoggerHelper.php';
}
//登录
function getUCUserLogin($sid){
if(!empty($sid)){
// $sid = "cst1mobi033d6f43069846be949bb161a473cf30147562";
$this->getUCBaseInit();
try{
$sidInfo = SDKServerService::verifySession($sid);
// echo $sidInfo->ucid;
// echo $sidInfo->nickName;
$arrRst['result'] = $this->resultSuccess;
$arrRst['data'] = $sidInfo;
} catch (SDKException $e){
// echo $e->getCode()." ".$e->getMessage();
$arrRst['result'] = $this->resultFailed;
$arrRst['infoError'] = array(
"code" => $e->getCode(),
"msg" => $e->getMessage(),
);
}
}
return empty($arrRst) ? array() : $arrRst;
}
//上传游戏数据
function getUCGameDataUpload($sid,$gameContent){
if(!empty($sid)){
$this->getUCBaseInit();
try{
$gameData = !empty($gameContent)&& is_array($gameContent) ? array($gameContent) : array();
$result = SDKServerService::gameData($sid, $gameData);
// if($result){echo "上传成功";};
$arrRst['result'] = $this->resultSuccess;
$arrRst['data'] = $result;
} catch (SDKException $e){
// echo $e->getCode()." ".$e->getMessage();
$arrRst['result'] = $this->resultFailed;
$arrRst['infoError'] = array(
"code" => $e->getCode(),
"msg" => $e->getMessage(),
);
}
}
return empty($arrRst) ? array() : $arrRst;
}
//玩家充值
function getUCPayCallBackService($dataPay){
// $arrRst = array(
// "data" => $dataPay,
// "result" => $this->resultSuccess,
// );
// return $arrRst;
try{
// 接收HTTP POST信息
//$request = file_get_contents("php://input");
// 测试数据
// $dataPay = '{"sign":"1ebc3d652404c8ac9b834a2aba9bb98a","data":{"failedDesc":"","amount":"30.0","callbackInfo":"serverip=sgall#channel=502#user=288287224.uc","accountId":"10000","creator":"JY","gameId":"1","payWay":"1","serverId":"1132","orderStatus":"S","orderId":"20120312113248863160","cpOrderId":"987654321"}}';
$this->getUCBaseInit();
$this->getUCPayInit();
LoggerHelper::info("[PayCallbackService.php]收到的支付回调的请求:".$dataPay);
// 处理支付回调请求
$responseData = json_decode($dataPay,true);
$arrRst['result'] = $this->resultFailed;
$arrRst['info'] = "FAILURE";
if($responseData!=null){
LoggerHelper::info("[PayCallbackService.php]"."[sign]:".$responseData['sign']);
LoggerHelper::info("[PayCallbackService.php]"."[orderId]:".$responseData['data']['orderId']);
LoggerHelper::info("[PayCallbackService.php]"."[gameId]:".$responseData['data']['gameId']);
LoggerHelper::info("[PayCallbackService.php]"."[accountId]:".$responseData['data']['accountId']);
LoggerHelper::info("[PayCallbackService.php]"."[creator]:".$responseData['data']['creator']);
LoggerHelper::info("[PayCallbackService.php]"."[payWay]:".$responseData['data']['payWay']);
LoggerHelper::info("[PayCallbackService.php]"."[amount]:".$responseData['data']['amount']);
LoggerHelper::info("[PayCallbackService.php]"."[callbackInfo]:".$responseData['data']['callbackInfo']);
LoggerHelper::info("[PayCallbackService.php]"."[orderStatus]:".$responseData['data']['orderStatus']);
LoggerHelper::info("[PayCallbackService.php]"."[failedDesc]:".$responseData['data']['failedDesc']);
$baseService = new BaseSDKService();
$signSource = $baseService->getSignData($responseData['data']).ConfigHelper::getStrVal("sdkserver.game.apikey");//组装签名原文
$sign = md5($signSource);//MD5加密签名
LoggerHelper::info("[PayCallbackService.php]"."[签名原文]:".$signSource);
LoggerHelper::info("[PayCallbackService.php]"."[签名结果]:".$sign);
if($sign == $responseData['sign']){
if ("S"==$responseData['data']['orderStatus']) {
LoggerHelper::info("[PayCallbackService.php]"."[处理结果]:"."SUCCESS");
$arrRst['result'] = $this->resultSuccess;
$arrRst['info'] = "SUCCESS";
}
}else{
LoggerHelper::info("[PayCallbackService.php]"."[处理结果]:"."FAILURE");
}
}else{
LoggerHelper::info("[PayCallbackService.php]"."接口返回异常");
}
return $arrRst;
}
catch (SDKException $e){
LoggerHelper::info("[PayCallbackService.php]".$e->getMessage());
// throw new exception($e->getMessage());
}
}
}