| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- namespace app\api\complex;
- /**
- * 九龙游戏 - V960
- */
- class Jlyx implements ComplexInterface
- {
- private $channel = 'jlyx';
- public $postHandleData = []; // 回调处理过的数据
- /**
- * ## 登陆 - 校验
- *
- * @param $data
- * @param $polyChannelGame
- *
- * @return false
- */
- public function getSpecialParam($data, $polyChannelGame = [])
- {
- // 参数:channel_token = token
- if (!isset($data['channel_token'])) {
- return false;
- }
- if (empty($polyChannelGame['param'])) {
- return false;
- }
- if (!$channelConfig = json_decode($polyChannelGame['param'], true)) {
- return false;
- }
- $param = [
- 'appId' => $channelConfig['app_id'],
- 'token' => $data['channel_token'],
- ];
- $param['sign'] = md5($param['appId'].$param['token'].$channelConfig['server_key']);
- $res = getHttpPost('http://user-api.yd999.com.cn/game/verify/token', $param);
- $res = json_decode($res, true);
- if ($res['code'] == 1) {
- return $res['data']['userId'];
- } else {
- return false;
- }
- }
- // ## 登陆 - 登陆
- public function checkLogin($data, $polyChannelGame = [])
- {
- return true;
- }
- // ## 下单 - 客户端需要的参数
- public function getOrder($data)
- {
- return ['code' => 200, 'msg' => 'success', 'param' => []];
- }
- // ## 回调 - 效验
- public function paySign($data, $polyChannelGame = [])
- {
- try {
- if (empty($data['data'])) {
- return false;
- }
- if (!$channelConfig = json_decode($polyChannelGame['param'], true)) {
- return false;
- }
-
- $postInput = urldecode($data['data']);
- $postData = $this->rsaDecode($postInput, $channelConfig['public_key']);
- if(!$postData){
- return false;
- }
- $postData = json_decode($postData, true);
- if (array_diff(['appId', 'userId', 'serverId', 'roleId', 'orderNum', 'orderMoneyFen', 'extInfo'], array_keys($postData))) {
- return false;
- }
- $param = [
- 'appId' => $postData['appId'],
- 'userId' => $postData['userId'],
- 'orderNum' => $postData['orderNum'],
- 'orderMoneyFen' => $postData['orderMoneyFen'],
- ];
- $param['sign'] = md5($param['appId'].$param['userId'].$param['orderNum'].$param['orderMoneyFen'].$channelConfig['server_key']);
- $res = getHttpPost('http://pay-center.yd999.com.cn/game_order_check', $param);
- // {"code":1,"msg":"订单校验成功","data":{"orderNum":"BR202411191745071616893946011","orderMoneyFen":"1"}}
- $res = json_decode($res, true);
- if ($res['code'] == 1) {
- $this->postHandleData = ['orderid' => $postData['orderNum'], 'amount' => $postData['orderMoneyFen'], 'sub_orderid' => $postData['extInfo']];
- return true;
- } else {
- return false;
- }
- } catch (\Exception $e){
- trace('jlyx: error=' . $e->getCode().' - '.$e->getMessage(), 'ComplexNotify.Exception');
- return false;
- }
- }
- // ## 回调 - 下单参数获取
- public function getData($data)
- {
- $data = $this->postHandleData;
- if (!isset($data['orderid']) || !isset($data['amount']) || !isset($data['sub_orderid'])) {
- return false;
- }
- return [
- 'orderid' => $data['sub_orderid'], // 我方聚合订单
- 'amount' => formatFenToYuan($data['amount']), // 充值金额(单位:元)
- 'sub_orderid' => $data['orderid'], // 渠道订单
- ];
- }
- // ## 回调 - 成功返回
- public function getSuccess($msg = '')
- {
- echo "SUCCESS";
- exit();
- }
- // ## 回调 - 失败返回
- public function getFail($msg = '')
- {
- echo "FAILURE:" . $msg;
- exit();
- }
-
- public function rsaDecode($dataStr = "", $publicKey = "")
- {
- $publicPem = $this->getPublicPem($publicKey);
- $data = base64_decode($dataStr);
- $crypto = '';
- $r = 0;
- foreach (str_split($data, 128) as $chunk) {
- $r = openssl_public_decrypt($chunk, $decrypted, $publicPem, OPENSSL_PKCS1_PADDING);
- $crypto .= $decrypted;
- }
- return $r ? $crypto : null;
- }
- private function getPublicPem($publicKey = "")
- {
- if (!$publicKey) {
- return "";
- }
- $publicKey = trim($publicKey);
- $needle = "BEGIN PUBLIC KEY";
- if (stripos($publicKey, $needle) !== false) {
- return openssl_pkey_get_public($publicKey);
- } else {
- $publicKey = str_replace(array("\r\n", "\n", "\r", " "), "", $publicKey);
- $key = chunk_split($publicKey, 64, "\r\n");//转换为pem格式的公钥
- $key = "-----BEGIN PUBLIC KEY-----\r\n" . $key . "-----END PUBLIC KEY-----";
- //输出key 可查看公钥格式后的原数据
- return openssl_pkey_get_public($key);
- }
- }
- }
|