Merge branch 'feature/testing_resource_admin' of wmtx/platform into master
测试资源功能优化master
commit
181b22969d
@ -0,0 +1,338 @@
|
||||
<extend name="Public/base"/>
|
||||
<block name="css">
|
||||
<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
|
||||
<link rel="stylesheet" href="__CSS__/promote.css" type="text/css"/>
|
||||
<script src="__STATIC__/laydate/laydate.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="__STATIC__/webuploader/webuploader.css" media="all">
|
||||
<style>
|
||||
.select2-container--open {
|
||||
z-index: 1001;
|
||||
}
|
||||
.select2-container--default .select2-selection--single {
|
||||
color: #000;
|
||||
resize: none;
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
border-color: #a7b5bc #ced9df #ced9df #a7b5bc;
|
||||
box-shadow: 0px 3px 3px #F7F8F9 inset;height:35px;
|
||||
height:28px;border-radius:3px;font-size:12px;
|
||||
}
|
||||
.select2-container--default .select2-selection--single .select2-selection__rendered {
|
||||
line-height:35px;
|
||||
line-height:28px;
|
||||
}
|
||||
.select2-container--default .select2-selection--single .select2-selection__arrow {
|
||||
height:26px;
|
||||
}
|
||||
.select2-container--default .select2-search--dropdown .select2-search__field {
|
||||
height:26px;line-height:26px;font-size:12px;
|
||||
}
|
||||
.select2-results__option[aria-selected] {font-size:12px;}
|
||||
.textarea-style {
|
||||
width: 200px;
|
||||
height: 80px;
|
||||
border-radius: 5px;
|
||||
padding: 5px;
|
||||
}
|
||||
.mustmark {
|
||||
color: #FF0000;
|
||||
font-style: normal;
|
||||
margin: 0 3px;
|
||||
}
|
||||
.clearfix:after {
|
||||
content: "\20";
|
||||
display: block;
|
||||
height: 0;
|
||||
clear: both;
|
||||
}
|
||||
.clearfix {
|
||||
*zoom: 1;
|
||||
}
|
||||
</style>
|
||||
</block>
|
||||
<block name="body">
|
||||
<script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="__JS__/select2.min.js"></script>
|
||||
<script type="text/javascript" src="__JS__/jquery.form.js"></script>
|
||||
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
|
||||
|
||||
<script src="__STATIC__/md5.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="__STATIC__/webuploader/webuploader.js"></script>
|
||||
<script src="__STATIC__/layer/layer.js" type="text/javascript"></script>
|
||||
<script type="text/javascript" src="__STATIC__/layer/extend/layer.ext.js"></script>
|
||||
<div class="cf main-place top_nav_list navtab_list">
|
||||
<h3 class="page_title">测试账号</h3>
|
||||
</div>
|
||||
<div class="cf top_nav_list">
|
||||
<!-- 高级搜索 -->
|
||||
<div class="fl button_list">
|
||||
<div class="tools">
|
||||
<empty name="show_status">
|
||||
<a class="fr" id="add-test-user" href="javascript:;"><span class="button_icon button_icon1"></span>新增测试账号</a>
|
||||
<!-- <a class="fr" id="batch_freeze"><span class="button_icon button_icon5 "></span>批量锁定</a>-->
|
||||
</empty>
|
||||
</div>
|
||||
</div>
|
||||
<div class="jssearch fl cf search_list">
|
||||
<div class="input-list search-title-box">
|
||||
<label>搜索:</label>
|
||||
</div>
|
||||
<div class="input-list">
|
||||
<input type="text" name="account" placeholder="测试账号" class="" value="" style="width: 150px">
|
||||
</div>
|
||||
<div class="input-list input-list-promote search_label_rehab">
|
||||
<select name="status" class="select_gallery" style="width:120px;">
|
||||
<option value="0">请选择状态</option>
|
||||
<?php foreach($statusList as $key => $value):?>
|
||||
<option value="<?=$key?>"><?=$value?></option>
|
||||
<?php endforeach;?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="input-list input-list-promote search_label_rehab">
|
||||
<input type="text" readonly name="create_time_start" class="time-select" value="{:I('create_time_start')}"
|
||||
placeholder="添加开始时间"/>
|
||||
-
|
||||
<div class="input-append date" id="datetimepicker" style="display:inline-block">
|
||||
<input type="text" readonly name="create_time_end" class="time-select" value="{:I('create_time_end')}"
|
||||
placeholder="添加结束时间"/>
|
||||
<span class="add-on"><i class="icon-th"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-list">
|
||||
<a class="sch-btn" href="javascript:;" id="search" url="{:U('TestingResource/users')}">搜索</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据列表 -->
|
||||
<div class="data_list">
|
||||
<div class="">
|
||||
<table>
|
||||
<!-- 表头 -->
|
||||
<thead>
|
||||
<tr>
|
||||
<th>测试账号</th>
|
||||
<th>账号状态</th>
|
||||
<th>推广员</th>
|
||||
<th>添加时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<!-- 列表 -->
|
||||
<tbody>
|
||||
<empty name ="records">
|
||||
<td colspan="99" class="text-center">aOh! 暂时还没有内容!</td>
|
||||
<else />
|
||||
<volist name="records" id="record">
|
||||
<tr data-user-id="{$record.user_id}">
|
||||
<td>{$record.user_account}</td>
|
||||
<td>{$record.status_text}</td>
|
||||
<td>{$record.promote_account}</td>
|
||||
<td>{$record.create_time}</td>
|
||||
<td>
|
||||
<?php if($record['status'] == 3):?>
|
||||
<a href="javascript:;" style="color: #3C95C8" class="unfreeze-btn">解禁</a>
|
||||
<?php else:?>
|
||||
<a href="javascript:;" style="color: #f56c6c" class="freeze-btn">禁用</a>
|
||||
<?php endif;?>
|
||||
</td>
|
||||
</tr>
|
||||
</volist>
|
||||
</empty>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="page">
|
||||
<if condition="$role_export_check eq true ">
|
||||
<a class="sch-btn export-btn"
|
||||
href="{:U(CONTROLLER_NAME.'/'.ACTION_NAME,array_merge(['export'=>1],I('get.')))}" target="_blank">导出</a>
|
||||
</if>
|
||||
{$_page|default=''}
|
||||
</div>
|
||||
|
||||
<div class="common_settings">
|
||||
<span class="plus_icon"><span><img src="__IMG__/zwmimages/icon_jia.png"></span></span>
|
||||
<form class="addShortcutIcon">
|
||||
<input type="hidden" name="title" value="{$m_title}">
|
||||
<input type="hidden" name="url" value="Query/withdraw">
|
||||
</form>
|
||||
<a class="ajax-post add-butn <notempty name='commonset'>addSIsetted</notempty>" href="javascript:;" target-form="addShortcutIcon" url="{:U('Think/addShortcutIcon')}"><img src="__IMG__/zwmimages/icon_jia.png"><span><notempty name='commonset'>已添加<else />添加至常用设置</notempty></span></a>
|
||||
</div>
|
||||
|
||||
<div id="add-box" class="layer-box" style="display: none;">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<div class="form-group">
|
||||
<label>用户账号</label>
|
||||
<div class="form-item" style="width: 400px;">
|
||||
<textarea name="accounts" placeholder="用户账号以英文逗号(,)隔开" class="form-input" id="" cols="50" rows="10"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label></label>
|
||||
<a id="add-submit" href="javascript:;" class="add-submit btn">确定</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</block>
|
||||
|
||||
<block name="script">
|
||||
<script src="__STATIC__/layer/layer.js" type="text/javascript"></script>
|
||||
<script type="text/javascript" src="__STATIC__/layer/extend/layer.ext.js" ></script>
|
||||
<script src="__STATIC__/jquery.cookie.js" charset="utf-8"></script>
|
||||
<script>
|
||||
<volist name=":I('get.')" id="vo">
|
||||
Think.setValue('{$key}',"{$vo}");
|
||||
</volist>
|
||||
$(".select_gallery").select2();
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
//导航高亮
|
||||
highlight_subnav("{:U('TestingResource/users')}");
|
||||
$(function(){
|
||||
// 添加全部选项
|
||||
if ('all' == "{:I('row', 0)}") {
|
||||
$("#pagechange").prepend("<option value='all' selected>全部</option>");
|
||||
} else {
|
||||
$("#pagechange").prepend("<option value='all'>全部</option>");
|
||||
}
|
||||
|
||||
$('.time-select').each(function(){
|
||||
laydate.render({
|
||||
elem: this,
|
||||
type: 'date'
|
||||
});
|
||||
});
|
||||
//搜索功能
|
||||
$("#search").click(function(){
|
||||
|
||||
var url = $(this).attr('url');
|
||||
var query = $('.jssearch').find('input').serialize();
|
||||
query += "&"+$('.jssearch').find('select').serialize();
|
||||
//query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
|
||||
query = query.replace(/^&/g,'');
|
||||
if( url.indexOf('?')>0 ){
|
||||
url += '&' + query;
|
||||
}else{
|
||||
url += '?' + query;
|
||||
}
|
||||
window.location.href = url;
|
||||
});
|
||||
//回车自动提交
|
||||
$('.jssearch').find('input').keyup(function(event){
|
||||
if(event.keyCode===13){
|
||||
$("#search").click();
|
||||
}
|
||||
});
|
||||
function getIds() {
|
||||
var ids = [];
|
||||
$('.ids:checked').each(function() {
|
||||
ids.push($(this).val());
|
||||
})
|
||||
return ids;
|
||||
}
|
||||
$('#add-test-user').click(function () {
|
||||
var box = $('#add-box')
|
||||
layer.open({
|
||||
title: '新增',
|
||||
type: 1,
|
||||
content: box,
|
||||
area: ['700px', '380px'],
|
||||
zIndex: 250,
|
||||
})
|
||||
})
|
||||
function isNumber(num){
|
||||
if(!num) {
|
||||
return false
|
||||
}
|
||||
var strPreg = /^\d+$/
|
||||
if(!strPreg.test(num)) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
$('.unfreeze-btn').click(function () {
|
||||
var tr = $(this).parents('tr').eq(0)
|
||||
var userId = tr.attr('data-user-id')
|
||||
layer.confirm('确定要解禁吗?', {
|
||||
// closeBtn:0,
|
||||
title: '解禁',
|
||||
btn: ['确定'] //按钮
|
||||
}, function(){
|
||||
$.ajax({
|
||||
async: false,
|
||||
url: "{:U('unfreezeTestingUser')}",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { user_id: userId },
|
||||
success: function (result) {
|
||||
if (result.status == 0) {
|
||||
layer.msg(result.message);
|
||||
} else {
|
||||
layer.msg(result.message, function(){
|
||||
window.location.href = window.location.href
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
$('.freeze-btn').click(function () {
|
||||
var tr = $(this).parents('tr').eq(0)
|
||||
var userId = tr.attr('data-user-id')
|
||||
layer.confirm('确定要禁用吗?', {
|
||||
// closeBtn:0,
|
||||
title: '禁用',
|
||||
btn: ['确定'] //按钮
|
||||
}, function(){
|
||||
$.ajax({
|
||||
async: false,
|
||||
url: "{:U('freezeTestingUser')}",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { user_id: userId },
|
||||
success: function (result) {
|
||||
if (result.status == 0) {
|
||||
layer.msg(result.message);
|
||||
} else {
|
||||
layer.msg(result.message, function(){
|
||||
window.location.href = window.location.href
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
$('#add-submit').on({
|
||||
click: function () {
|
||||
var box = $('#add-box')
|
||||
var accounts = box.find('[name=accounts]').val()
|
||||
console.log(accounts)
|
||||
$.ajax({
|
||||
async: false,
|
||||
url: "{:U('addTestingUsers')}",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { accounts: accounts },
|
||||
success: function (result) {
|
||||
if (result.status == 0) {
|
||||
layer.msg(result.message);
|
||||
} else {
|
||||
var message = '成功' + result.data.successCount + '个, 失败' + result.data.errorCount + '个, 已存在' + result.data.existCount + '个。'
|
||||
layer.confirm(message, {
|
||||
btn: ['确定'] //按钮
|
||||
}, function(){
|
||||
location.reload();
|
||||
})
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</block>
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Base\Tool;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
use Base\Tool\GameResource\YzchzbClient;
|
||||
use Base\Tool\GameResource\LsxxClient;
|
||||
use Base\Tool\GameResource\JtxcClient;
|
||||
|
||||
/**
|
||||
* 游戏资源接口
|
||||
*/
|
||||
class GameResource
|
||||
{
|
||||
private $client;
|
||||
private $game;
|
||||
|
||||
private $clientMap = [
|
||||
191 => JtxcClient::class,
|
||||
192 => JtxcClient::class,
|
||||
231 => LsxxClient::class,
|
||||
232 => LsxxClient::class,
|
||||
229 => YzchzbClient::class,
|
||||
230 => YzchzbClient::class,
|
||||
];
|
||||
|
||||
public function __construct($game)
|
||||
{
|
||||
$this->game = $game;
|
||||
$this->client = $this->createClient();
|
||||
}
|
||||
|
||||
private function createClient()
|
||||
{
|
||||
$clientClass = '';
|
||||
$gameId = intval($this->game['id']);
|
||||
if (isset($this->clientMap[$gameId])) {
|
||||
$clientClass = $this->clientMap[$gameId];
|
||||
} else {
|
||||
throw new \Exception('游戏资源客户端未配置');
|
||||
}
|
||||
return new $clientClass();
|
||||
}
|
||||
|
||||
public function getResourceTypes()
|
||||
{
|
||||
$deviceType = $this->game['sdk_version'] == 1 ? 'andriod' : 'ios';
|
||||
return $this->client->getResourceTypes($deviceType);
|
||||
}
|
||||
|
||||
public function getResources($typeId = null)
|
||||
{
|
||||
$deviceType = $this->game['sdk_version'] == 1 ? 'andriod' : 'ios';
|
||||
return $this->client->getResources($typeId, $deviceType);
|
||||
}
|
||||
|
||||
public function apply($order, $role)
|
||||
{
|
||||
return $this->client->apply($order, $role);
|
||||
}
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace Base\Tool\GameResource;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
/**
|
||||
* 九天仙尘-测试资源接口
|
||||
*/
|
||||
class JtxcClient
|
||||
{
|
||||
const SIGN_NAME = 'sign';
|
||||
const SUCCESS = '0000';
|
||||
|
||||
const KEY = '6c9VLnZFlhEppATKKWeH5vV900K6Nhy5';
|
||||
|
||||
protected $client;
|
||||
|
||||
// http://chat.leniu.com/api/game/sendGold/zhuimeng/jxlm/57972
|
||||
private $apis = [
|
||||
'provide' => ['uri' => '/api/game/sendGold/zhuimeng/jxlm/57972', 'method' => 'post'],
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new Client([
|
||||
'base_uri' => 'http://chat.leniu.com',
|
||||
'timeout' => 10.0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function api($api, array $params = [])
|
||||
{
|
||||
$api = $this->apis[$api] ?? null;
|
||||
if (is_null($api)) {
|
||||
throw new \Exception('接口不存在');
|
||||
}
|
||||
$params[self::SIGN_NAME] = $this->sign($params);
|
||||
try {
|
||||
return $this->request($api, $params);
|
||||
} catch (\Exception $e) {
|
||||
$env = C('APP_ENV', null, 'prod');
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function request($api, $params)
|
||||
{
|
||||
if ($api['method'] == 'get') {
|
||||
return $this->get($api['uri'], $params);
|
||||
} else {
|
||||
return $this->post($api['uri'], $params);
|
||||
}
|
||||
}
|
||||
|
||||
protected function post($uri, array $params = [])
|
||||
{
|
||||
$response = $this->client->post($uri, [
|
||||
'verify' => false,
|
||||
'form_params' => $params,
|
||||
]);
|
||||
return (string)$response->getBody();
|
||||
}
|
||||
|
||||
protected function get($uri, array $params = [])
|
||||
{
|
||||
$response = $this->client->get($uri, [
|
||||
'verify' => false,
|
||||
'query' => $params,
|
||||
]);
|
||||
return (string)$response->getBody();
|
||||
}
|
||||
|
||||
protected function sign($params)
|
||||
{
|
||||
unset($params[self::SIGN_NAME]);
|
||||
ksort($params);
|
||||
$signRows = [];
|
||||
foreach ($params as $key => $value) {
|
||||
$signRows[] = $key . '=' . $value;
|
||||
}
|
||||
return md5(implode('&', $signRows) . self::KEY);
|
||||
}
|
||||
|
||||
public function apply($order, $role)
|
||||
{
|
||||
$result = $this->api('provide', [
|
||||
'role_id' => $role['role_id'],
|
||||
'money' => intval($order['ref_amount']) * 10,
|
||||
'type' => 2,
|
||||
// 'goods_id' => 0,
|
||||
'server_no' => $role['server_id'],
|
||||
]);
|
||||
if ($result == 'SUCCESS') {
|
||||
return [
|
||||
'status' => true,
|
||||
'message' => $result,
|
||||
'result' => ['result' => $result]
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => false,
|
||||
'message' => $result,
|
||||
'result' => ['result' => $result]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function getResourceTypes($deviceType)
|
||||
{
|
||||
if ($deviceType == 'andriod') {
|
||||
return [['id' => 1, 'name' => '通用', 'device_type' => 'andriod']];
|
||||
} elseif ($deviceType == 'ios') {
|
||||
return [['id' => 2, 'name' => '通用', 'device_type' => 'ios']];
|
||||
}
|
||||
}
|
||||
|
||||
public function getResources($typeId, $deviceType)
|
||||
{
|
||||
return [
|
||||
1 => ['ref_id' => 1, 'name' => '60元宝', 'amount' => 6],
|
||||
2 => ['ref_id' => 2, 'name' => '300元宝', 'amount' => 30],
|
||||
3 => ['ref_id' => 3, 'name' => '980元宝', 'amount' => 98],
|
||||
4 => ['ref_id' => 4, 'name' => '1280元宝', 'amount' => 128],
|
||||
5 => ['ref_id' => 5, 'name' => '1980元宝', 'amount' => 198],
|
||||
6 => ['ref_id' => 6, 'name' => '3280元宝', 'amount' => 328],
|
||||
7 => ['ref_id' => 7, 'name' => '6480元宝', 'amount' => 648],
|
||||
8 => ['ref_id' => 8, 'name' => '10000元宝', 'amount' => 1000],
|
||||
9 => ['ref_id' => 9, 'name' => '20000元宝', 'amount' => 2000],
|
||||
10 => ['ref_id' => 10, 'name' => '30000元宝', 'amount' => 3000],
|
||||
11 => ['ref_id' => 11, 'name' => '50000元宝', 'amount' => 5000],
|
||||
12 => ['ref_id' => 12, 'name' => '100000元宝', 'amount' => 10000],
|
||||
13 => ['ref_id' => 13, 'name' => '200000元宝', 'amount' => 20000],
|
||||
14 => ['ref_id' => 14, 'name' => '680元宝', 'amount' => 68],
|
||||
];
|
||||
|
||||
/* return [
|
||||
['ref_id' => 121209, 'name' => '6元充值卡', 'amount' => 6],
|
||||
['ref_id' => 121210, 'name' => '30元充值卡', 'amount' => 30],
|
||||
['ref_id' => 121211, 'name' => '98元充值卡', 'amount' => 98],
|
||||
['ref_id' => 121212, 'name' => '128元充值卡', 'amount' => 128],
|
||||
['ref_id' => 121213, 'name' => '198元充值卡', 'amount' => 198],
|
||||
['ref_id' => 121214, 'name' => '328元充值卡', 'amount' => 328],
|
||||
['ref_id' => 121215, 'name' => '648元充值卡', 'amount' => 648],
|
||||
['ref_id' => 121216, 'name' => '1000元充值卡', 'amount' => 1000],
|
||||
['ref_id' => 121217, 'name' => '2000元充值卡', 'amount' => 2000],
|
||||
['ref_id' => 121218, 'name' => '3000元充值卡', 'amount' => 3000],
|
||||
['ref_id' => 121219, 'name' => '5000元充值卡', 'amount' => 5000],
|
||||
['ref_id' => 121220, 'name' => '10000元充值卡', 'amount' => 10000],
|
||||
['ref_id' => 121221, 'name' => '20000元充值卡', 'amount' => 20000],
|
||||
['ref_id' => 121222, 'name' => '68元充值卡', 'amount' => 68],
|
||||
]; */
|
||||
}
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Base\Tool\GameResource;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
/**
|
||||
* 乱世枭雄-测试资源接口
|
||||
*/
|
||||
class LsxxClient
|
||||
{
|
||||
const SIGN_NAME = 'sign';
|
||||
const KEY = 'vtc5f7q9zp8ztsbf';
|
||||
|
||||
protected $client;
|
||||
|
||||
private $apis = [
|
||||
'get-pay-type' => ['uri' => '/wanmeng/prop.php', 'method' => 'get'],
|
||||
'provide' => ['uri' => '/wanmeng/prop.php?action=prop', 'method' => 'post'],
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new Client([
|
||||
'base_uri' => 'http://47.114.91.166:1096',
|
||||
'timeout' => 10.0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function api($api, array $params = [])
|
||||
{
|
||||
$api = $this->apis[$api] ?? null;
|
||||
if (is_null($api)) {
|
||||
throw new \Exception('接口不存在');
|
||||
}
|
||||
$params[self::SIGN_NAME] = $this->sign($params);
|
||||
try {
|
||||
return $this->request($api, $params);
|
||||
} catch (\Exception $e) {
|
||||
$env = C('APP_ENV', null, 'prod');
|
||||
return ['status' => 0, 'msg' => '接口请求错误。' . ($env == 'prod' ? '' : $e->getMessage()) , 'data' => []];
|
||||
}
|
||||
}
|
||||
|
||||
public function request($api, $params)
|
||||
{
|
||||
if ($api['method'] == 'get') {
|
||||
return $this->get($api['uri'], $params);
|
||||
} else {
|
||||
return $this->post($api['uri'], $params);
|
||||
}
|
||||
}
|
||||
|
||||
protected function post($uri, array $params = [])
|
||||
{
|
||||
$response = $this->client->post($uri, [
|
||||
'verify' => false,
|
||||
'form_params' => $params,
|
||||
]);
|
||||
$result = (string)$response->getBody();
|
||||
return json_decode($result, true);
|
||||
}
|
||||
|
||||
protected function get($uri, array $params = [])
|
||||
{
|
||||
$response = $this->client->get($uri, [
|
||||
'verify' => false,
|
||||
'query' => $params,
|
||||
]);
|
||||
$result = (string)$response->getBody();
|
||||
return json_decode($result, true);
|
||||
}
|
||||
|
||||
protected function sign($params)
|
||||
{
|
||||
unset($params[self::SIGN_NAME]);
|
||||
ksort($params);
|
||||
$signRows = [];
|
||||
foreach ($params as $key => $value) {
|
||||
$signRows[] = $key . '=' . $value;
|
||||
}
|
||||
return md5(implode('&', $signRows) . self::KEY);
|
||||
}
|
||||
|
||||
public function apply($order, $role)
|
||||
{
|
||||
$result = $this->api('provide', [
|
||||
'role_id' => $role['role_id'],
|
||||
'goods_id' => $order['ref_id'],
|
||||
'server_no' => $role['server_id'],
|
||||
'send_time' => time()
|
||||
]);
|
||||
if ($result['status'] == 1) {
|
||||
return [
|
||||
'status' => true,
|
||||
'message' => $result['msg'],
|
||||
'result' => $result
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => false,
|
||||
'message' => $result['msg'],
|
||||
'result' => $result ?? []
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function getResourceTypes($deviceType)
|
||||
{
|
||||
if ($deviceType == 'andriod') {
|
||||
return [['id' => 1, 'name' => '通用', 'device_type' => 'andriod']];
|
||||
} elseif ($deviceType == 'ios') {
|
||||
return [['id' => 2, 'name' => '通用', 'device_type' => 'ios']];
|
||||
}
|
||||
}
|
||||
|
||||
public function getResources($typeId, $deviceType)
|
||||
{
|
||||
$resources = [];
|
||||
$result = $this->api('get-pay-type', ['action' => 'getItems']);
|
||||
if ($result['status'] == 1) {
|
||||
$items = $result['data'];
|
||||
foreach ($items as $item) {
|
||||
$resources[$item['id']] = [
|
||||
'ref_id' => $item['id'],
|
||||
'name' => $item['name'],
|
||||
'amount' => $item['money'],
|
||||
];
|
||||
}
|
||||
}
|
||||
return $resources;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Base\Tool;
|
||||
|
||||
class IPTool
|
||||
{
|
||||
public static function getIpInfo($ip)
|
||||
{
|
||||
$host = 'https://api01.aliyun.venuscn.com';
|
||||
$path = '/ip';
|
||||
$method = 'GET';
|
||||
$appcode = '244181f0846541a19e24df409736d3b9';
|
||||
$headers = [];
|
||||
array_push($headers, 'Authorization:APPCODE ' . $appcode);
|
||||
$querys = 'ip=' . $ip;
|
||||
$bodys = '';
|
||||
$url = $host . $path . '?' . $querys;
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
// curl_setopt($curl, CURLOPT_HEADER, true);
|
||||
if (1 == strpos('$'.$host, 'https://')) {
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
}
|
||||
$response = curl_exec($curl);
|
||||
if (!$response) {
|
||||
return null;
|
||||
}
|
||||
$result = json_decode($response, true);
|
||||
if ($result['ret'] == 200) {
|
||||
return $result['data'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue