| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace app\api\complex;
- use think\Request;
- /**
- * 91玩 H5
- */
- class Jywanh5 implements ComplexInterface
- {
- private $channel = 'Jywanh5';
- /**
- * ## 登陆 - 校验
- *
- * @param $data
- * @param $polyChannelGame
- *
- * @return false
- */
- public function getSpecialParam($data, $polyChannelGame = [])
- {
- // 参数:user_id = user_id
- return $data['user_id'];
- }
- // ## 登陆 - 登陆
- public function checkLogin($data, $polyChannelGame = [])
- {
- // 参数:user_id = user_id, extparam = {'channelExt':'', 'agent_id':'', 'game_appid':'', 'timestamp':'', 'loginplatform2cp':'', 'user_id':'', 'birthday':'', 'sign':''}
- if (empty($data['user_id']) || empty($data['extparam'])) {
- return false;
- }
- $extparam = json_decode($data['extparam'], true);
- if (empty($extparam)) {
- return false;
- }
- if (empty($polyChannelGame['param'])) {
- return false;
- }
- if (!$channelConfig = json_decode($polyChannelGame['param'], true)) {
- return false;
- }
- $sign = $this->signData($extparam, $channelConfig['game_key']);
- if ($extparam['sign'] === $sign) {
- return ['user_id' => $extparam['user_id']];
- }
- return false;
- }
- // ## 回调 - 效验
- public function paySign($data, $polyChannelGame = [])
- {
- if (!$channelConfig = json_decode($polyChannelGame['param'], true)) {
- return false;
- }
- $param = Request::instance()->only(['game_order', 'out_trade_no', 'pay_extra', 'pay_status', 'price', 'user_id', 'sign']);
- $sign = $data['sign'];
- $hadleSign = $this->signData($param, $channelConfig['game_key']);
- if ($sign == $hadleSign) {
- return true;
- }
- return false;
- }
- // ## 回调 - 下单参数获取
- public function getData($data)
- {
- if (!isset($data['game_order']) || !isset($data['price']) || !isset($data['out_trade_no'])) {
- return false;
- }
- return [
- 'orderid' => $data['game_order'], // 我方聚合订单
- 'amount' => $data['price'], // 充值金额(单位:元)
- 'sub_orderid' => $data['out_trade_no'], // 渠道订单
- ];
- }
- // ## 回调 - 成功返回
- public function getSuccess($msg = '')
- {
- echo 'success';
- exit();
- }
- // ## 回调 - 失败返回
- public function getFail($msg = '')
- {
- log_message('getFail: '.$msg, 'error', LOG_PATH."complexPaylog/{$this->channel}/");
- echo 'fail';
- exit();
- }
- // 签名
- private function signData($param, $game_key)
- {
- unset($param['sign']);
- ksort($param);
- foreach ($param as $k => $v) {
- $tmp[] = $k . '=' . urlencode($v);
- }
- $str = implode('&', $tmp) . $game_key;
- return md5($str);
- }
- }
|