| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace app\api\complex;
- use ComplexThree\JuLe\joloRsa;
- /**
- * 聚乐
- */
- class Jule implements ComplexInterface
- {
- private $channel = 'jule';
- /**
- * ## 登陆 - 校验
- *
- * @param $data
- * @param $polyChannelGame
- *
- * @return false
- */
- public function getSpecialParam($data, $polyChannelGame = [])
- {
- if (empty($data['extparam']) || empty($data['channel_token'])) {
- return false;
- }
-
- if (!$paramArr = json_decode($polyChannelGame['param'], true)) {
- return false;
- }
- $rsa = new joloRsa();
- $ret = $rsa->verification_sign($data['extparam'], $data['channel_token'], $paramArr['htc_key']);
- if (!$ret) {
- return false;
- }
- $account = json_decode($data['extparam'], true);
- if (isset($account['user_code'])) {
- return $account['user_code'];
- } else {
- return false;
- }
- }
- // ## 登陆 - 登陆
- public function checkLogin($data, $polyChannelGame = [])
- {
- return true;
- }
- // ## 下单 - 客户端需要的参数(客户端自己做了,这块暂时不用)
- public function getOrder($data)
- {
- // ## 测试
- // $data['user_code'] = '104471097';
- // $data['session_id'] = '12842658';
- // $data['rolename'] = '无';
- // $data['rolelevel'] = '无';
- // $data['roleid'] = '无';
- // $data['serverid'] = '无';
- if (empty(array_intersect_key($data, ['user_code', 'session_id', 'rolename', 'rolelevel', 'roleid', 'serverid']))) {
- return ['code' => 100, 'msg' => '下单参数有误!', 'param' => []];
- }
- if (empty($data['channel_info']['param'])) {
- return ['code' => 100, 'msg' => '渠道配置参数有误!', 'param' => []];
- }
- $param = $data['channel_infox']['param'];
- $param = json_decode($param, true);
- $orderArr['game_name'] = $data['game_info']['nickname']; // 游戏名称
- $orderArr['game_code'] = $param['app_id']; // 游戏编号(gamecode)
- $orderArr['game_order_id'] = $data['pay_info']['orderid']; // 游戏订单id
- $orderArr['amount'] = formatYuanToFen($data['pay_info']['amount']); // 金额,单位为分
- $orderArr['notify_url'] = $data['notify_url']; // 支付回调地址
- $orderArr['product_id'] = $data['product_id'] ?? '无'; //商品ID
- $orderArr['product_name'] = $data['product_name'] ?? '无'; //商品名称
- $orderArr['product_des'] = $data['product_des'] ?? '无'; //商品描述
- $orderArr['user_code'] = $data['user_code']; // 聚乐用户编号
- $orderArr['session_id'] = $data['session_id']; // 聚乐登录凭证session_id
- $orderArr['role_name'] = $data['rolename']; // 游戏角色名
- $orderArr['role_level'] = $data['rolelevel']; // 游戏角色等级
- $orderArr['area_server'] = $data['area_server'] ?? '无'; // 游戏区服名称
- $orderArr['vip_level'] = $data['vip_level'] ?? '无'; //游戏vip等级
- $orderArr['role_id'] = $data['roleid']; // 游戏角色ID
- $orderArr['area_server_id'] = $data['serverid']; // 游戏区服ID
- $orderArr['channel_reserved '] = ""; //cp自定义字段返回
- $rsa = new joloRsa();
- $private_key = config('complex.ju_le')['private_key_pkcs8'];
- $result = $rsa->order_rsa_sign($orderArr, $private_key);
- if ($result) {
- $orderArr['sign '] = $result; // 签名
- return ['code' => 200, 'msg' => 'success', 'param' => $orderArr];
- }
- return ['code' => 100, 'msg' => '渠道配置参数有误!', 'param' => $orderArr];
- }
- // ## 回调 - 效验
- public function paySign($data, $polyChannelGame = [])
- {
- /**
- * $data['order'] = order="{"result_code":1,"gmt_create":"2024-03-06 16:30:24","real_amount":6,"result_msg":"支付成功","game_code":"3417175059607","game_order_id":"CMWL17097137368704152218","jolo_order_id":"ZF1072602186b443c9ffe9af051","gmt_payment":"2024-03-06 16:30:41","channel_reserved":""}"&sign="fNo3mRVb6p3grMtpEg01B/EfUl6isqiV3CgdgKBg6M6vJoT1RnBUfspCZttp1wv5b7E01EXeFue1tTw4iCS/JEYucb30parkdOzHe81CDHhLNcOCDFueMMN+75yGZ1TDgpDRsTvoMNUZa5bp4FmorYGLMEIKK6poDZ4sQJi4OA4="&sign_type="RSA"
- */
- if(empty($polyChannelGame['param'])){
- return false;
- }
- if (!$paramArr = json_decode($polyChannelGame['param'], true)) {
- return false;
- }
- if (!isset($data['order']) || !isset($data['sign'])) {
- return false;
- }
- $order = substr(urldecode($data['order']), 1, -1);
- $sign = substr($data['sign'], 1, -1);
- $sign = str_replace(' ', '+', $sign);
- $rsa = new joloRsa();
- $pub_key = $rsa->setupPubKey($paramArr['htc_key']);
- $dataStatus = $rsa->rsa_verify($order, $sign, $pub_key);
- if (!$dataStatus) {
- return false;
- }
- $orderData = json_decode($order, true);
- if ($orderData['result_code'] == 1) {
- return true;
- }
- return false;
- }
- // ## 回调 - 下单参数获取
- public function getData($data)
- {
- $order = substr(urldecode($data['order']), 1, -1);
- $orderData = json_decode($order, true);
- return [
- 'orderid' => $orderData['game_order_id'], // 我方聚合订单
- 'amount' => formatFenToYuan($orderData['real_amount']), // 充值金额(单位:元)
- 'sub_orderid' => $orderData['jolo_order_id'], // 渠道订单
- ];
- }
- // ## 回调 - 成功返回
- public function getSuccess($msg = '')
- {
- echo 'success';
- exit();
- }
- // ## 回调 - 失败返回
- public function getFail($msg = '')
- {
- echo 'success';
- exit();
- }
- }
|