DouYinService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <?php
  2. namespace app\api\service;
  3. use app\adminapi\logic\external\ExternalConsultationLogic;
  4. use app\api\logic\ServiceOrderLogic;
  5. use app\common\model\Config;
  6. use app\common\model\external\DouyinOrder;
  7. use app\common\model\external\DouyinRefundOrder;
  8. use app\common\model\external\ExternalConsultation;
  9. use app\common\model\external\ExternalConsultationOrder;
  10. use app\common\model\goods\Goods;
  11. use app\common\model\recharge\RechargeOrder;
  12. use app\common\model\user\User;
  13. use app\common\model\user\UserAuth;
  14. use app\common\model\works\ServiceWork;
  15. use app\common\service\ConfigService;
  16. use app\common\service\FileService;
  17. use think\facade\Db;
  18. use think\facade\Log;
  19. class DouYinService
  20. {
  21. protected static int $terminal = \app\common\enum\user\UserTerminalEnum::DOUYIN;
  22. protected static int $external_platform_id = 6;
  23. // ********************************* 注册登录
  24. public static function register(array $params)
  25. {
  26. $userSn = User::createUserSn();
  27. $params['password'] = !empty($params['password'])?$params['password']:rand(100000,999999);
  28. $passwordSalt = \think\facade\Config::get('project.unique_identification');
  29. $password = create_password($params['password'], $passwordSalt);
  30. $avatar = ConfigService::get('default_image', 'user_avatar');
  31. $user = User::create([
  32. 'sn' => $userSn,
  33. 'avatar' => $avatar,
  34. 'nickname' => '用户' . $userSn,
  35. 'account' => $params['account'],
  36. 'mobile' => !empty($params['mobile'])?$params['mobile']:'',
  37. 'password' => $password,
  38. 'channel' => self::$terminal,
  39. 'user_type' => $params['user_type']??0,
  40. ]);
  41. return $user;
  42. }
  43. public static function phoneLogin(array $params)
  44. {
  45. try {
  46. $where = ['mobile' => $params['mobile']];
  47. $params['account'] = $params['mobile'];
  48. $user = User::where($where)->findOrEmpty();
  49. if ($user->isEmpty()) {
  50. //直接注册用户
  51. $params['channel'] = self::$terminal;
  52. $user = self::register($params);
  53. }
  54. //更新登录信息
  55. $user->login_time = time();
  56. $user->login_ip = request()->ip();
  57. $user->save();
  58. $userInfo = UserTokenService::setToken($user->id, self::$terminal);
  59. //返回登录信息
  60. $avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
  61. $avatar = FileService::getFileUrl($avatar);
  62. return [
  63. 'nickname' => $userInfo['nickname'],
  64. 'sn' => $userInfo['sn'],
  65. 'mobile' => $userInfo['mobile'],
  66. 'avatar' => $avatar,
  67. 'token' => $userInfo['token'],
  68. ];
  69. } catch (\Exception $e) {
  70. throw new \Exception($e->getMessage());
  71. }
  72. }
  73. // **************************** 商品管理
  74. /*/product/save/ 先调
  75. goods/sku/batch_save/ 再调
  76. 生成 产品组装
  77. 生成 sku 组装
  78. 生成对应的 attr_key_value_map 组装*/
  79. public static function getProductParams($type,$params)
  80. {
  81. return [];
  82. }
  83. public static function getSkuParams($type,$params)
  84. {
  85. return [];
  86. }
  87. public static function getAttrKeyValueMapParams($type,$params)
  88. {
  89. return [];
  90. }
  91. /**
  92. * 提交订单
  93. * @param array $params
  94. * @return array|false
  95. */
  96. public static function submitOrder($params)
  97. {
  98. Db::startTrans();
  99. try {
  100. $goods = Goods::findOrEmpty($params['goods_id']);
  101. if($goods->isEmpty()){
  102. throw new \Exception('产品不存在!');
  103. }
  104. if(empty($params['user_info']['mobile'])){
  105. throw new \Exception('请先补充您的联系方式后在提交订单');
  106. }
  107. // TODO tmp防抖1m
  108. $isExist = DouyinOrder::where(['user_id'=>$params['user_id'],'goods_id'=>$goods['id']])->where('create_time','>',(time() - 60))->findOrEmpty();
  109. if(!$isExist->isEmpty()){
  110. throw new \Exception('请勿重复下单!');
  111. }
  112. $quantity = $params['quantity']??1;
  113. //生成订单
  114. $create_data = [
  115. 'user_id' => $params['user_id'],
  116. 'mobile' => $params['user_info']['mobile'],
  117. 'title' => $goods['goods_name'],
  118. 'goods_id'=>$goods['id'],
  119. 'unit_price' => $goods['service_fee'],
  120. 'quantity' => $quantity,
  121. 'total_amount' => $goods['service_fee'] * $quantity,
  122. 'order_number' => generate_sn(DouyinOrder::class, 'order_number'),
  123. ];
  124. $order = DouyinOrder::create($create_data);
  125. Db::commit();
  126. return $create_data['order_number'];
  127. } catch (\Exception $e) {
  128. Db::rollback();
  129. throw new \Exception($e->getMessage());
  130. }
  131. }
  132. public static function getByteAuthorization($order_number)
  133. {
  134. /*{
  135. "skuList": [{
  136. "skuId": "商品ID",
  137. "price": 100,//单价-分
  138. "quantity": 1,
  139. "title": "商品标题",
  140. "imageList": ["https://cdn.weixiu.kyjlkj.com/uploads/images/20240914/202409141528015aeaa2357.png"],
  141. "type": 701,
  142. "tagGroupId": "tag_group_7272625659887960076"
  143. }],
  144. "outOrderNo": "202411121413333930",
  145. "totalAmount": 100,//分
  146. "orderEntrySchema": {
  147. "path": "page/path/index",
  148. "params": '{"id":1234, "name":"hello"}'
  149. },
  150. "payNotifyUrl": "https://weixiudev.kyjlkj.com/api/dou_yin/payNotify"
  151. }*/
  152. try {
  153. $douyinOrder = DouyinOrder::where('order_number',$order_number)->findOrEmpty();
  154. if($douyinOrder->isEmpty()){
  155. throw new \Exception('订单不存在!');
  156. }
  157. $order = $douyinOrder->toArray();
  158. $goods_image = Goods::where('id',$order['goods_id'])->value('goods_image')??'';
  159. $data = [
  160. "skuList" => [
  161. [
  162. "skuId" => (string)$order['goods_id'],
  163. "price" => $order['unit_price'] * 100,
  164. "quantity" => $order['quantity'],
  165. "title" => $order['title'],
  166. "imageList" => [$goods_image],
  167. "type" => 701,
  168. "tagGroupId" => "tag_group_7272625659887960076"
  169. ]
  170. ],
  171. "outOrderNo" => $order['order_number'],
  172. "totalAmount" => $order['total_amount'] * 100,
  173. "orderEntrySchema" => [
  174. "path" => "page/index/index",
  175. "params" => json_encode(['order_number' => $order['order_number']])
  176. ],
  177. "payNotifyUrl" => config('douyin.payNotifyUrl'),
  178. ];
  179. $byteAuthorization = self::byteAuthorization(config('douyin.privateKeyStr'), json_encode($data), config('douyin.appId'), self::randStr(10), time(), 1);
  180. return ['byteAuthorization'=>$byteAuthorization,'data'=>json_encode($data)];
  181. } catch (\Exception $e) {
  182. throw new \Exception($e->getMessage());
  183. }
  184. }
  185. public static function cancelOrder($params)
  186. {
  187. // $params['order_number']
  188. Db::startTrans();
  189. try {
  190. $order = DouyinOrder::where('order_number', $params['order_number'])->findOrEmpty();
  191. if(!$order->isEmpty()){
  192. if($order->order_status == 1 && $order->pay_status == 0){
  193. $order->order_status = 4;
  194. $order->save();
  195. }else{
  196. throw new \Exception('订单状态不可取消!');
  197. }
  198. }
  199. Db::commit();
  200. return $order['id'];
  201. } catch (\Exception $e) {
  202. Db::rollback();
  203. throw new \Exception($e->getMessage());
  204. }
  205. }
  206. public static function payNotify($params)
  207. {
  208. Log::write(json_encode($params));
  209. // 查询抖音订单是否完成支付
  210. if ($params['status'] === 'SUCCESS') {
  211. $transaction_id = $params['order_id']??'';
  212. $paid_amount = bcdiv(bcsub($params['total_amount'] ,$params['discount_amount']), '100', 2)??0;
  213. $out_order_no = $params['out_order_no'];
  214. $pay_time = $params['event_time']??time();
  215. $order = DouyinOrder::where('order_number', $out_order_no)->findOrEmpty();
  216. if(!$order->isEmpty()){
  217. // 更新充值订单状态
  218. $order->transaction_id = $transaction_id;
  219. $order->order_status = 2;
  220. $order->pay_time = $pay_time;
  221. $order->paid_amount = $paid_amount;
  222. $user = User::where('id',$order->user_id)->findOrEmpty()->toArray();
  223. $form_detail = [
  224. 'user_name' => $user['real_name']??'',
  225. 'mobile' => $user['mobile'],
  226. 'transaction_id' => $transaction_id,
  227. 'out_trade_no' => $out_order_no,
  228. 'paid_amount' => $paid_amount,
  229. 'params' => $params,
  230. ];
  231. $consultation = ExternalConsultation::create([
  232. 'external_platform_id' => self::$external_platform_id,
  233. 'form_detail' => json_encode($form_detail),
  234. 'user_name' => $user['real_name']??'',
  235. 'mobile' => $user['mobile'],
  236. 'goods_id' => $order->goods_id,
  237. 'amount' => $paid_amount
  238. ]);
  239. $order->consultation_id = $consultation->id;
  240. $order->save();
  241. return true;
  242. }
  243. }
  244. return false;
  245. }
  246. public static function reservation($params)
  247. {
  248. /*$lon_lat = get_address_lat_lng($params['user_address']);
  249. $params['lon'] = $lon_lat['lon'];
  250. $params['lat'] = $lon_lat['lat'];*/
  251. // $params['order_number']
  252. Db::startTrans();
  253. try {
  254. $order = DouyinOrder::where('order_number', $params['order_number'])->findOrEmpty();
  255. if(!$order->isEmpty()){
  256. $consultation = ExternalConsultation::where('id', $order->consultation_id)->findOrEmpty()->toArray();
  257. $consultation['user_name'] = $params['user_name']??$consultation['user_name'];
  258. $consultation['mobile'] = $params['mobile']??$consultation['mobile'];
  259. $consultation['user_address'] = $params['user_address'];
  260. $consultation['lon'] = $params['lon'];
  261. $consultation['lat'] = $params['lat'];
  262. $consultation['appointment_time'] = $params['appointment_time'];
  263. $result = ExternalConsultationLogic::order($consultation);
  264. if (false === $result) {
  265. throw new \Exception('预约失败');
  266. }
  267. $consultationOrder = ExternalConsultationOrder::where('consultation_id', $order->consultation_id)->where('goods_id', $order->goods_id)->where('amount', $order->paid_amount)
  268. ->findOrEmpty()->toArray();
  269. $work_status = ServiceWork::where('id', $consultationOrder['work_id'])->value('work_status');
  270. $order->work_id = $consultationOrder['work_id'];
  271. $order->fulfillment_status = $work_status;
  272. $order->save();
  273. }
  274. Db::commit();
  275. return $order['id'];
  276. } catch (\Exception $e) {
  277. Db::rollback();
  278. throw new \Exception($e->getMessage());
  279. }
  280. }
  281. public static function upReservation($params)
  282. {
  283. // $params['order_number']
  284. Db::startTrans();
  285. try {
  286. $order = DouyinOrder::where('order_number', $params['order_number'])->findOrEmpty();
  287. if(!$order->isEmpty()){
  288. // sn appointment_time
  289. $result = ServiceOrderLogic::approvalChangeAppointment(['sn'=>RechargeOrder::where('work_id', $order->work_id)->value('sn'),'appointment_time'=>$params['appointment_time']]);
  290. if (false === $result) {
  291. throw new \Exception(ServiceOrderLogic::getError());
  292. }
  293. $order->fulfillment_status = ServiceWork::where('id', $order->work_id)->value('work_status');
  294. $order->save();
  295. }
  296. Db::commit();
  297. return $order['id'];
  298. } catch (\Exception $e) {
  299. Db::rollback();
  300. throw new \Exception($e->getMessage());
  301. }
  302. }
  303. public static function getOrderDetail($params)
  304. {
  305. //抖音订单信息/商品信息/预约信息(地址、时间、履约状态与信息)
  306. // $params['order_number'] user_id
  307. $order = DouyinOrder::with(['goods','serviceWork','douyinRefundOrder'])->where('order_number', $params['order_number'])->where('user_id', $params['user_id'])->findOrEmpty();
  308. if($order->isEmpty()){
  309. return [];
  310. }
  311. $orderInfo = $order->toArray();
  312. empty($orderInfo['goods']) && $orderInfo['goods'] = [];
  313. empty($orderInfo['serviceWork']) && $orderInfo['serviceWork'] = [];
  314. empty($orderInfo['douyinRefundOrder']) && $orderInfo['douyinRefundOrder'] = [];
  315. $work_status = $orderInfo['serviceWork']['work_status']??0;
  316. $performance = [];
  317. // tmp
  318. switch ($work_status){
  319. case 0:
  320. $performance[] = ['status' => '待派单','title' => '待派单','time' => date('Y-m-d H:i:s',time())];
  321. break;
  322. case 1:
  323. case 2:
  324. case 3:
  325. $performance[] = ['status' => '待派单','title' => '待派单','time' => date('Y-m-d H:i:s',time())];
  326. $performance[] = ['status' => '已派单','title' => '已派单','time' => date('Y-m-d H:i:s',time())];
  327. break;
  328. case 4:
  329. case 5:
  330. case 6:
  331. $performance[] = ['status' => '待派单','title' => '待派单','time' => date('Y-m-d H:i:s',time())];
  332. $performance[] = ['status' => '已派单','title' => '已派单','time' => date('Y-m-d H:i:s',time())];
  333. $performance[] = ['status' => '服务中','title' => '服务中','time' => date('Y-m-d H:i:s',time())];
  334. break;
  335. case 7:
  336. case 8:
  337. $performance[] = ['status' => '待派单','title' => '待派单','time' => date('Y-m-d H:i:s',time())];
  338. $performance[] = ['status' => '已派单','title' => '已派单','time' => date('Y-m-d H:i:s',time())];
  339. $performance[] = ['status' => '服务中','title' => '服务中','time' => date('Y-m-d H:i:s',time())];
  340. $performance[] = ['status' => '已完结','title' => '已完结','time' => date('Y-m-d H:i:s',time())];
  341. break;
  342. }
  343. $orderInfo['performance'] = $performance;
  344. return $orderInfo;
  345. }
  346. public static function refund($params)
  347. {
  348. Db::startTrans();
  349. try {
  350. // $params['order_number'] user_id
  351. $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $params['order_number'])->where('user_id', $params['user_id'])->findOrEmpty();
  352. if($order->isEmpty()){
  353. throw new \Exception('订单不存在');
  354. }
  355. $orderInfo = $order->toArray();
  356. $work_status = $orderInfo['serviceWork']['work_status']??0;
  357. if(3 < $work_status){
  358. throw new \Exception('该订单禁止退款');
  359. }
  360. DouyinRefundOrder::create([
  361. 'refund_number' => generate_sn(DouyinRefundOrder::class, 'refund_number'),
  362. 'order_number' => $orderInfo['order_number'],
  363. 'transaction_id' => $orderInfo['transaction_id'],
  364. 'reason' => $params['reason']??'',
  365. 'refund_status' => 0,
  366. 'user_id' => $orderInfo['user_id'],
  367. 'refund_amount' => $orderInfo['paid_amount'],
  368. ]);
  369. Db::commit();
  370. return true;
  371. } catch (\Exception $e) {
  372. Db::rollback();
  373. throw new \Exception($e->getMessage());
  374. }
  375. }
  376. public static function refundExamine($params)
  377. {
  378. Db::startTrans();
  379. try {
  380. // $params['order_number']
  381. $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $params['order_number'])->findOrEmpty();
  382. if($order->isEmpty()){
  383. throw new \Exception('订单不存在');
  384. }
  385. $orderInfo = $order->toArray();
  386. //$refund_number = $params['refund_number']??'';
  387. $douyinRefundOrder = DouyinRefundOrder::where('order_number', $params['order_number'])->order('id', 'desc')->findOrEmpty();
  388. if($params['is_examine_ok'] === 'pass'){
  389. $douyinRefundOrder->refund_status = 2;
  390. RechargeOrder::where('work_id', $orderInfo['work_id'])->update([
  391. 'pay_status' => 2,
  392. 'pay_time' => 0,
  393. 'paid_amount' => 0,
  394. ]);
  395. ServiceWork::where('id', $orderInfo['work_id'])->update([
  396. 'work_status' => 0,
  397. 'user_confirm_status' => 0,
  398. 'service_status' => 4,
  399. 'work_pay_status' => 0
  400. ]);
  401. }else{
  402. $douyinRefundOrder->refund_status = 1;
  403. }
  404. $douyinRefundOrder->save();
  405. Db::commit();
  406. if($params['is_examine_ok'] === 'pass'){
  407. //通过后向抖音申请退款
  408. self::sendRefundCreate($params['order_number']);
  409. }
  410. return true;
  411. } catch (\Exception $e) {
  412. Db::rollback();
  413. throw new \Exception($e->getMessage());
  414. }
  415. }
  416. public static function sendRefundCreate($order_number)
  417. {
  418. try {
  419. // $params['order_number']
  420. $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $order_number)->findOrEmpty();
  421. if($order->isEmpty()){
  422. throw new \Exception('订单不存在');
  423. }
  424. $orderInfo = $order->toArray();
  425. $douyinRefundOrder = DouyinRefundOrder::where('order_number', $order_number)->order('id', 'desc')->findOrEmpty();
  426. //通过后向抖音申请退款
  427. //getClientToken()
  428. $url = config('douyin.host').'api/trade_basic/v1/developer/refund_create/';
  429. $data = [
  430. "order_id" => $orderInfo['transaction_id'],
  431. "out_refund_no" => $douyinRefundOrder->refund_number,
  432. "cp_extra" => $orderInfo['id'].'|'.$douyinRefundOrder->id,
  433. "order_entry_schema" => [
  434. "path" => "page/index/index",
  435. "params" => json_encode(['refund_number'=>$douyinRefundOrder->refund_number])
  436. ],
  437. "refund_total_amount " => $douyinRefundOrder->refund_amount * 100,
  438. "notify_url" => config('douyin.refundNotifyUrl'),
  439. "refund_reason" => [
  440. [
  441. "code" => 101,
  442. "text" => "不想要了"
  443. ]
  444. ]
  445. ];
  446. $res = http_request($url,$data,['Content-Type' => 'application/json;charset=utf-8','access_token' => self::getClientToken()]);
  447. if(isset($res['err_msg']) && $res['err_msg'] === 'success'){
  448. $douyinRefundOrder->transaction_id = $res['data']['refund_id'];
  449. $douyinRefundOrder->save();
  450. }
  451. return true;
  452. } catch (\Exception $e) {
  453. Log::info($e->getMessage());
  454. return false;
  455. }
  456. }
  457. public static function refundNotify($params)
  458. {
  459. Db::startTrans();
  460. try {
  461. $douyinRefundOrder = DouyinRefundOrder::where('refund_number', $params['out_refund_no'])->findOrEmpty();
  462. if($douyinRefundOrder->isEmpty()){
  463. throw new \Exception('退款订单不存在');
  464. }
  465. if($douyinRefundOrder->refund_status == 0){
  466. if($params['status'] === 'SUCCESS'){
  467. $douyinRefundOrder->refund_status = 3;
  468. DouyinOrder::where('order_number', $douyinRefundOrder->order_number)->update([
  469. 'order_status' => 4,
  470. 'pay_status' => 3,
  471. ]);
  472. }elseif($params['status'] === 'FAIL'){
  473. $douyinRefundOrder->refund_status = 4;
  474. }else{
  475. throw new \Exception('退款状态未知');
  476. }
  477. $douyinRefundOrder->save();
  478. }
  479. Db::commit();
  480. return true;
  481. } catch (\Exception $e) {
  482. Db::rollback();
  483. throw new \Exception($e->getMessage());
  484. }
  485. }
  486. /**
  487. * 扩展点回调提交订单
  488. * @param $params
  489. * @return bool
  490. * @throws \Exception
  491. * @author liugc <466014217@qq.com>
  492. * @date 2025/6/4 14:03
  493. */
  494. public static function submitOrderNotify($params)
  495. {
  496. Db::startTrans();
  497. try {
  498. Db::commit();
  499. return true;
  500. } catch (\Exception $e) {
  501. Db::rollback();
  502. throw new \Exception($e->getMessage());
  503. }
  504. }
  505. public static function byteAuthorization($privateKeyStr, $data, $appId, $nonceStr, $timestamp, $keyVersion) {
  506. $byteAuthorization = '';
  507. // 读取私钥
  508. $privateKey = openssl_pkey_get_private($privateKeyStr);
  509. if (!$privateKey) {
  510. throw new \Exception("Invalid private key");
  511. }
  512. // 生成签名
  513. $signature = self::getSignature("POST", "/requestOrder", $timestamp, $nonceStr, $data, $privateKey);
  514. if ($signature === false) {
  515. return null;
  516. }
  517. // 构造 byteAuthorization
  518. $byteAuthorization = sprintf("SHA256-RSA2048 appid=%s,nonce_str=%s,timestamp=%s,key_version=%s,signature=%s", $appId, $nonceStr, $timestamp, $keyVersion, $signature);
  519. return $byteAuthorization;
  520. }
  521. public static function getSignature($method, $url, $timestamp, $nonce, $data, $privateKey) {
  522. Log::info("method:{$method}\n url:{$url}\n timestamp:{$timestamp}\n nonce:{$nonce}\n data:{$data}");
  523. $targetStr = $method. "\n" . $url. "\n" . $timestamp. "\n" . $nonce. "\n" . $data. "\n";
  524. openssl_sign($targetStr, $sign, $privateKey, OPENSSL_ALGO_SHA256);
  525. $sign = base64_encode($sign);
  526. return $sign;
  527. }
  528. public static function randStr($length = 8) {
  529. $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  530. $str = '';
  531. for ($i = 0; $i < $length; $i++) {
  532. $str .= $chars[mt_rand(0, strlen($chars) - 1)];
  533. }
  534. return $str;
  535. }
  536. public static function getClientToken($isRefresh = false) {
  537. $url = config('douyin.host').'oauth/client_token/';
  538. $cache_name = 'dy_client_token';
  539. $cache_data = cache($cache_name);
  540. if(empty($cache_data) || $cache_data == null || $isRefresh){
  541. $data = [
  542. 'client_key'=> config('douyin.appId'),
  543. 'client_secret'=> config('douyin.appSecret'),
  544. 'grant_type'=> "client_credential"
  545. ];
  546. $res = http_request($url,$data,['Content-Type' => 'application/json;charset=utf-8']);
  547. Log::info(json_encode($res));
  548. if($res['message'] === 'success'){
  549. cache($cache_name, json_encode($res['data']), (time()+$res['data']['expires_in']-1));
  550. $cache_data = $res['data'];
  551. }
  552. }
  553. return $cache_data['access_token'];
  554. }
  555. }