| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace app\api\complex;
- header('Content-Type:text/html;charset=UTF-8');
- /**
- * 爱游
- */
- class Aiyou implements ComplexInterface
- {
- private $channel = 'aiyou';
- // 登陆效验
- public function checkLogin($data, $polyChannelGame = [])
- {
- if(empty($data['user_id']) || empty($data['channel_token'])){
- return false;
- }
- if (!$paramArr = json_decode($polyChannelGame['param'], true)) {
- return false;
- }
- $param = [
- 'userID' => $data['user_id'],
- 'token' => $data['channel_token'],
- ];
- $signStr = sprintf('token=%s&userID=%s&key=%s', $param['token'], $param['userID'], $paramArr['appSecret']);
- $param['sign'] = md5($signStr);
- $result = get_http_response('https://iu-gateway.iyouhuyu.com/iug-sdk/user/verifyAccount', $param);
- $res = json_decode($result, true);
- if ($res['state'] == 1) {
- return true;
- } else {
- return false;
- }
- }
- // 下单参数
- public function getData($data)
- {
- return [
- 'orderid' => $data['extension'], //我方聚合订单
- 'amount' => formatFenToYuan($data['money']), // 充值金额(单位:元)
- 'sub_orderid' => $data['orderID'], //渠道订单
- ];
- }
- // 回调效验
- public function paySign($data, $polyChannelGame = [])
- {
- if (!$paramArr = json_decode($polyChannelGame['param'], true)) {
- return false;
- }
- $newData = [
- 'productID' => $data['productID'],
- 'orderID' => $data['orderID'],
- 'userID' => $data['userID'],
- 'channelID' => $data['channelID'],
- 'gameID' => $data['gameID'],
- 'serverID' => $data['serverID'],
- 'money' => $data['money'],
- 'currency' => $data['currency'],
- 'extension' => $data['extension'],
- 'roleID' => $data['roleID'],
- 'signType' => $data['signType'],
- 'sign' => $data['sign'],
- ];
- $sign = $this->sign($newData, $paramArr['appSecret']);
- if ($newData['sign'] == $sign) {
- return true;
- }
- return false;
- }
- /**
- * 生成签名
- *
- * @param array $data 参数数组
- * @param string $appSecret 密钥
- *
- * @return string 签名
- */
- function sign($data, $appSecret)
- {
- $newData = [];
- // 对参数进行 URL 解码
- foreach ($data as $key => $value) {
- if (!in_array($key, ['roleID', 'signType', 'sign'])) {
- $newData[$key] = urldecode($value);
- }
- }
- // 对参数进行首字母升序排序
- ksort($newData);
- // 拼接参数
- $signStr = '';
- foreach ($newData as $key => $value) {
- $signStr .= $key . '=' . $value . '&';
- }
- // 拼接密钥
- $signStr .= $appSecret;
- // 对字符串进行 MD5 签名
- $sign = md5($signStr);
- // dump($signStr, $sign);
- return $sign;
- }
- public function getFail($msg = '')
- {
- echo 'FAIL';
- exit();
- }
- public function getSuccess($msg = '')
- {
- echo 'SUCCESS';
- exit();
- }
- /**
- * 二次登陆效验
- *
- * @param $data
- * @param $polyChannelGame
- *
- * @return false
- */
- public function getSpecialParam($data,$polyChannelGame = [])
- {
- if(empty($data['user_id']) || empty($data['channel_token'])){
- return false;
- }
- if (!$paramArr = json_decode($polyChannelGame['param'], true)) {
- return false;
- }
- $param = [
- 'userID' => $data['user_id'],
- 'token' => $data['channel_token'],
- ];
- $signStr = sprintf('token=%s&userID=%s&key=%s', $param['token'], $param['userID'], $paramArr['appSecret']);
- $param['sign'] = md5($signStr);
- $result = get_http_response('https://iu-gateway.iyouhuyu.com/iug-sdk/user/verifyAccount', $param);
- $res = json_decode($result, true);
- if ($res['state'] == 1) {
- return (string)$res['data']['userID'];
- } else {
- return false;
- }
- }
- }
|