| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- namespace app\api\complex;
- use think\Config;
- /**
- * 三九互娱
- */
- class Sanjiu implements ComplexInterface
- {
- private $channel = 'sanjiu';
- /**
- * ## 登陆 - 校验
- *
- * @param $data
- * @param $polyChannelGame
- *
- * @return false
- */
- public function getSpecialParam($data, $polyChannelGame = [])
- {
- // 参数:user_id = juhe_userid, channel_token = juhe_token, extparam = channel_userid
- if (!isset($data['user_id']) || !isset($data['channel_token']) || !isset($data['extparam'])) {
- return false;
- }
- if (empty($polyChannelGame['param'])) {
- return false;
- }
- if (!$channelConfig = json_decode($polyChannelGame['param'], true)) {
- return false;
- }
- $param = [
- 'juhe_userid' => $data['user_id'],
- 'juhe_token' => $data['channel_token'],
- 'app_id' => $channelConfig['app_id'],
- 'channel_userid' => $data['extparam'],
- ];
- $param['sign'] = $this->signLogin($param, $channelConfig['payment_key']);
- $res = get_http_response('https://juhesdk.3975ad.com/api/oauth/verify_token', $param);
- $res = json_decode($res, true);
- if ($res['success'] == true) {
- return $data['user_id'];
- } else {
- return false;
- }
- }
- // ## 登陆 - 登陆
- public function checkLogin($data, $polyChannelGame = [])
- {
- return true;
- }
- // ## 下单 - 客户端需要的参数(客户端自己做了,这块暂时不用)
- public function getOrder($data)
- {
- // 渠道游戏支付金额的产品标识获取
- $prefix = isComplexProduct($data['channel_mark'], $data['gameid']);
- if(!$prefix){
- return ['code' => 200, 'msg' => 'success', 'param' => "{}"];
- }
- if (!isset(config('config_complex_goods')[$prefix])) {
- return ['code' => 100, 'msg' => '当前渠道的游戏未配置商品:' . $prefix.' - '.$data['gameid'] . ' - ' . $data['amount'], 'param' => "{}"];
- }
- $cp_money = formatComplexProductMark($prefix, $data['gameid'], $data['amount']);
- if (!$cp_money) {
- return ['code' => 100, 'msg' => '当前渠道的游戏配置商品不存在: '. $prefix.' - '. $data['gameid'] . '-' . $data['amount'], 'param' => "{}"];
- }
- return ['code' => 200, 'msg' => 'success', 'param' => ['product_money_mark' => $cp_money, 'money' => $data['amount']]];
- }
- // ## 回调 - 效验
- public function paySign($data, $polyChannelGame = [])
- {
- // {"net_status":"WIFI","server_name":"区服名称","app_version":"1","bundleid":"com.qimeng.channel","unix_name":"产品名称","sign":"9218599D095E70EFDB9FF394D3311E1C","role_level":"1","package_id":"14821","channel_version":"9.9.8","uuid":"","mac":"0","platform":"2","product_desc":"产品描述","device_name":"GLK-AL00","role_id":"202005201314","product_id":"sanjiu_kdzz_0000100","juhesdk_version":"5.0.3","idfv":"","channel_userid":"0","wifi_ssid":"0","idfa":"","product_num":"1","server_id":"1","version":"10","role_name":"龙天","app_name":"channelSdk","net_isp":"UNKNOWN","money":"1","extends":"","user_id":"231971664","app_build_version":"1.0","cp_order_id":"CMWL17174002974091640934","imei":"dad55fca2b3cd65b","device_user_name":"unknown","ip":"183.156.238.137","ext":"0","juhe_order_id":"jh751-17df1664e288f7","is_sandbox":"0","real_money":"1"}
- $handleKeys = ['cp_order_id', 'package_id', 'channel_userid', 'money', 'unix_name', 'ext', 'juhe_order_id', 'sign'];
- if (array_diff($handleKeys, array_keys($data))) {
- return false;
- }
- $param = [
- 'cp_order_id' => $data['cp_order_id'],
- 'package_id' => $data['package_id'],
- 'channel_userid' => $data['channel_userid'],
- 'money' => $data['money'],
- 'unix_name' => $data['unix_name'],
- 'ext' => $data['ext'],
- 'juhe_order_id' => $data['juhe_order_id'],
- 'sign' => $data['sign'],
- ];
- if (!$channelConfig = json_decode($polyChannelGame['param'], true)) {
- return false;
- }
- $hadleSign = $this->signNotify($param, $channelConfig['payment_key'], true);
- if ($data['sign'] == $hadleSign) {
- return true;
- }
- return false;
- }
- // ## 回调处理相关参数
- public function getData($data)
- {
- if (!isset($data['cp_order_id']) || !isset($data['money']) || !isset($data['juhe_order_id'])) {
- return false;
- }
- return [
- 'orderid' => $data['cp_order_id'], // 我方聚合订单
- 'amount' => $data['money'], // 充值金额(单位:元)
- 'sub_orderid' => $data['juhe_order_id'], // 渠道订单
- ];
- }
- // ## 回调 - 成功返回
- public function getSuccess($msg = '')
- {
- echo 'success';
- exit();
- }
- // ## 回调 - 失败返回
- public function getFail($msg = '')
- {
- echo 'fail';
- exit();
- }
- // 登陆签名
- private function signLogin($param, $app_key)
- {
- ksort($param);
- $sign = http_build_query($param) . $app_key;
- $md5Res = strtoupper(md5($sign));
- trace('sign=' . $sign . ' - md5=' . $md5Res, 'Sanjiu@signLogin.result');
- return $md5Res;
- }
- // 回调签名
- private function signNotify($param, $app_key)
- {
- $oldSign = $param['sign'];
- unset($param['sign']);
- ksort($param);
- $string = '';
- foreach ($param as $k => $v) {
- $string .= $k. $v;
- // if ($string) {
- // } else {
- // $string = $k. $v;
- // }
- }
- $sign = $string. $app_key;
- $md5Res = strtoupper(md5($sign));
- trace('str=' . $sign . ' - sign: ' .$oldSign.' - '. $md5Res, 'Sanjiu@signNotify.result');
- return $md5Res;
- }
- }
|