getMessage(); } } /** * 查询账户余额 * @author php迷途小书童 * @created 2021/1/14 16:34 */ public static function checkAmount($user) { $cardType = $user['card_type'] ? $user['card_type'] : 10; $cxbData = [ 'platformNo' => env('GZC.PLATFORM_NO'), 'appNo' => env('GZC.APP_NO'), 'conName' => $user['user_name'], 'conCertType' => $cardType, 'conCertNo' => $user['user_card'], ]; Log::info('储蓄保养老金请求参数:' . json_encode($cxbData)); $cxbResponseData = self::request('POST', '/v1/api/third/in/in30', $cxbData, [], 1); Log::info('储蓄保养老金请求返回:' . json_encode($cxbResponseData)); if($cxbResponseData['code'] != 0) { return $cxbResponseData['message']; } $xfbData = [ 'platformNo' => env('XINGFUBAO.PLATFORM_NO'), 'appNo' => env('XINGFUBAO.APP_NO'), 'conName' => $user['user_name'], 'conCertType' => $cardType, 'conCertNo' => $user['user_card'], ]; Log::info('幸福保养老金请求参数:' . json_encode($xfbData)); $xfbResponseData = self::request('POST', '/v1/api/third/in/in30', $xfbData, [], 2); Log::info('幸福保养老金请求返回:' . json_encode($xfbResponseData)); if($xfbResponseData['code'] != 0) { return $xfbResponseData['message']; } $amount = $cxbResponseData['extendData']['amount'] + $xfbResponseData['extendData']['amount']; return $amount; } public function getAmountFromGzc() { $uid = $this->request->uid(); $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find(); if (empty($userInfo['user_name']) || empty($userInfo['user_card'])) { Log::error('[getAmountFromGzc] 用户实名信息缺失', ['uid' => $uid, 'userInfo' => $userInfo]); return app('json')->fail('未找到用户实名信息'); } try { $res = GzcApiRequest::checkAmount($userInfo); } catch (\Throwable $e) { Log::error('[getAmountFromGzc] 调用异常', ['uid' => $uid, 'error' => $e->getMessage()]); return app('json')->fail('查询失败(第三方异常)'); } if (!is_array($res) || ($res['code'] ?? -1) !== 0) { return app('json')->fail($res['message'] ?? '查询失败'); } $amountCents = $res['extendData']['amount'] ?? $res['data']['amount'] ?? $res['amount'] ?? 0; $amount = floatval($amountCents) * 0.01; $formatted = sprintf('%.2f', $amount); return app('json')->success([ 'amount' => $formatted, 'debug' => $res['debug'] ?? null, ]); } /** * 获取TOKEN * @return mixed|string * @author php迷途小书童 * @created 2021/1/14 14:38 */ public static function getTokenFromServer($type = 1) { $timestamp = (int)(microtime(true) * 1000); if ($type == 1) { $appid = env('GZC.APP_ID'); }else{ $appid = env('XINGFUBAO.APP_ID'); } $data = [ 'appid' => $appid, 'sign' => self::getSignContent($timestamp, $appid, $type), 'timestamp' => $timestamp ]; return self::request('POST', '/v1/api/third/auth/token', $data); } /** * 获取签名 * @return string * @author php迷途小书童 * @created 2020/10/29 9:35 */ public static function getSignContent(int $timestamp, string $appid, $type = 1) { if ($type == 1) { $appsecret = md5(env('GZC.APP_SECRET')); }else{ $appsecret = md5(env('XINGFUBAO.APP_SECRET')); } $stringToBeSigned = "appid={$appid}&secret={$appsecret}×tamp={$timestamp}"; return md5($stringToBeSigned); } }