['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 [ 121264 => ['ref_id' => 121264, 'name' => '私人定制12元激活卡', 'amount' => 12], 121246 => ['ref_id' => 121246, 'name' => '私人定制30元激活卡', 'amount' => 30], 121247 => ['ref_id' => 121247, 'name' => '私人定制68元激活卡', 'amount' => 68], 121248 => ['ref_id' => 121248, 'name' => '私人定制128元激活卡', 'amount' => 128], 121249 => ['ref_id' => 121249, 'name' => '私人定制198元激活卡', 'amount' => 198], 121250 => ['ref_id' => 121250, 'name' => '私人定制328元激活卡', 'amount' => 328], 121251 => ['ref_id' => 121251, 'name' => '私人定制648元激活卡', 'amount' => 648], 121228 => ['ref_id' => 121228, 'name' => '1元礼包激活卡', 'amount' => 1], 121229 => ['ref_id' => 121229, 'name' => '6元礼包激活卡', 'amount' => 6], 121230 => ['ref_id' => 121230, 'name' => '30元礼包激活卡', 'amount' => 30], 121252 => ['ref_id' => 121252, 'name' => '68元礼包激活卡', 'amount' => 68], 121253 => ['ref_id' => 121253, 'name' => '98元礼包激活卡', 'amount' => 98], 121254 => ['ref_id' => 121254, 'name' => '128元礼包激活卡', 'amount' => 128], 121255 => ['ref_id' => 121255, 'name' => '198元礼包激活卡', 'amount' => 198], 121256 => ['ref_id' => 121256, 'name' => '328元礼包激活卡', 'amount' => 328], 121257 => ['ref_id' => 121257, 'name' => '648元礼包激活卡', 'amount' => 648], 121262 => ['ref_id' => 121262, 'name' => '钻石特权30元卡', 'amount' => 30], 121209 => ['ref_id' => 121209, 'name' => '6元专属充值卡', 'amount' => 6], 121210 => ['ref_id' => 121210, 'name' => '30元专属充值卡', 'amount' => 30], 121222 => ['ref_id' => 121222, 'name' => '68元专属充值卡', 'amount' => 68], 121211 => ['ref_id' => 121211, 'name' => '98元专属充值卡', 'amount' => 98], 121212 => ['ref_id' => 121212, 'name' => '128元专属充值卡', 'amount' => 128], 121213 => ['ref_id' => 121213, 'name' => '198元专属充值卡', 'amount' => 198], 121214 => ['ref_id' => 121214, 'name' => '328元专属充值卡', 'amount' => 328], 121215 => ['ref_id' => 121215, 'name' => '648元专属充值卡', 'amount' => 648], 121216 => ['ref_id' => 121216, 'name' => '1000元专属充值卡', 'amount' => 1000], 121217 => ['ref_id' => 121217, 'name' => '2000元专属充值卡', 'amount' => 2000], 121218 => ['ref_id' => 121218, 'name' => '3000元专属充值卡', 'amount' => 3000], 121219 => ['ref_id' => 121219, 'name' => '5000元专属充值卡', 'amount' => 5000], 121220 => ['ref_id' => 121220, 'name' => '10000元专属充值卡', 'amount' => 10000], 121221 => ['ref_id' => 121221, 'name' => '20000元专属充值卡', 'amount' => 20000], ]; } }