|
@@ -0,0 +1,45 @@
|
|
|
+<?php
|
|
|
+namespace app\service\byte_dance;
|
|
|
+use GuzzleHttp\Client;
|
|
|
+
|
|
|
+class ByteDance{
|
|
|
+ public static function accessToken(){
|
|
|
+ return self::single(ByteDanceAccessToken::class)
|
|
|
+ ->setAppId(self::appId())
|
|
|
+ ->setAppSecret(self::appSecret())
|
|
|
+ ->get();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static function single($class){
|
|
|
+ static $container=[];
|
|
|
+ if (!isset($container[$class])){
|
|
|
+ $container[$class]=new $class;
|
|
|
+ }
|
|
|
+ return $container[$class];
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function appId(){
|
|
|
+ return config('site.byte_dance_mapp_appId');
|
|
|
+ }
|
|
|
+ public static function appSecret(){
|
|
|
+ return config('site.byte_dance_mapp_appSecret');
|
|
|
+ }
|
|
|
+ public static function httpGet($url){
|
|
|
+ $request=(new Client)
|
|
|
+ ->get($url);
|
|
|
+ return json_decode($request->getBody()->getContents(),true);
|
|
|
+ }
|
|
|
+ public static function httpPost($url,$params,$header=[]){
|
|
|
+ $request=(new Client)
|
|
|
+ ->request('post',$url,[
|
|
|
+ 'json'=>$params,
|
|
|
+ 'headers'=>$header
|
|
|
+ ]);
|
|
|
+ return json_decode($request->getBody()->getContents(),true);
|
|
|
+ }
|
|
|
+ public static function throwIf($condition,$msg){
|
|
|
+ if($condition){
|
|
|
+ throw new ByteDanceException($msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|