First commit
This commit is contained in:
60
.env
Executable file
60
.env
Executable file
@@ -0,0 +1,60 @@
|
||||
APP_DEBUG = true
|
||||
DEV_MODE = false
|
||||
|
||||
[APP]
|
||||
DEFAULT_TIMEZONE = Asia/Shanghai
|
||||
|
||||
[DATABASE]
|
||||
TYPE = mysql
|
||||
HOSTNAME = "127.0.0.1"
|
||||
DATABASE = "zhncxt"
|
||||
USERNAME = "zhncxt"
|
||||
PASSWORD = "zhncxt"
|
||||
|
||||
|
||||
|
||||
#HOSTNAME =
|
||||
#DATABASE =
|
||||
#USERNAME =
|
||||
#PASSWORD =
|
||||
HOSTPORT = 3306
|
||||
CHARSET = utf8mb4
|
||||
DEBUG = true
|
||||
PREFIX = ims_
|
||||
|
||||
[LANG]
|
||||
default_lang = zh-cn
|
||||
|
||||
[CACHE]
|
||||
driver = redis
|
||||
host = 127.0.0.1
|
||||
passwd =
|
||||
prefix = longyiyi_
|
||||
expire = 0
|
||||
|
||||
[SESSION]
|
||||
NAME = longyiyiSession
|
||||
TYPE = redis
|
||||
EXPIRE = 3600
|
||||
PREFIX = longyiyiSession_
|
||||
|
||||
[RABBIT]
|
||||
RABBIT_HOST = 127.0.0.1
|
||||
RABBIT_PORT = 5672
|
||||
RABBIT_LOGIN = guest
|
||||
RABBIT_PASSWORD = guest
|
||||
RABBIT_VHOST = 'longyiyi'
|
||||
RABBIT_QOS_LIMIT = 1
|
||||
EXCHANGE_NAME = longyiyi_exchange
|
||||
QUERY_NAME = longyiyi_query
|
||||
KEY = key
|
||||
|
||||
[SCHEDULER]
|
||||
|
||||
[swoole]
|
||||
port = 8001
|
||||
host = 0.0.0.0
|
||||
daemonize = false
|
||||
|
||||
[log]
|
||||
channel = file
|
||||
53
.env.example
Executable file
53
.env.example
Executable file
@@ -0,0 +1,53 @@
|
||||
APP_DEBUG = true
|
||||
|
||||
[APP]
|
||||
DEFAULT_TIMEZONE = Asia/Shanghai
|
||||
|
||||
[DATABASE]
|
||||
TYPE = mysql
|
||||
HOSTNAME = "127.0.0.1"
|
||||
DATABASE = "longbingtest"
|
||||
USERNAME = "longbingtest"
|
||||
PASSWORD = "123"
|
||||
#HOSTNAME =
|
||||
#DATABASE =
|
||||
#USERNAME =
|
||||
#PASSWORD =
|
||||
HOSTPORT = 3306
|
||||
CHARSET = utf8mb4
|
||||
DEBUG = true
|
||||
PREFIX = ims_
|
||||
|
||||
[LANG]
|
||||
default_lang = zh-cn
|
||||
|
||||
[CACHE]
|
||||
driver = redis
|
||||
host = 127.0.0.1
|
||||
passwd =
|
||||
prefix = longbing_
|
||||
expire = 0
|
||||
|
||||
[SESSION]
|
||||
NAME = lonngbingSession
|
||||
TYPE = redis
|
||||
EXPIRE = 3600
|
||||
PREFIX = LongBingSession_
|
||||
|
||||
[RABBIT]
|
||||
RABBIT_HOST = 127.0.0.1
|
||||
RABBIT_PORT = 5672
|
||||
RABBIT_LOGIN = guest
|
||||
RABBIT_PASSWORD = guest
|
||||
RABBIT_VHOST = '/'
|
||||
RABBIT_QOS_LIMIT = 1
|
||||
EXCHANGE_NAME = longbing_exchange
|
||||
QUERY_NAME = longbing_query
|
||||
KEY = key
|
||||
|
||||
[SCHEDULER]
|
||||
|
||||
[SWOOLE]
|
||||
PORT = 8005
|
||||
HOST = 0.0.0.0
|
||||
|
||||
BIN
ErBiao-0.0.1-SNAPSHOT.jar
Executable file
BIN
ErBiao-0.0.1-SNAPSHOT.jar
Executable file
Binary file not shown.
32
LICENSE.txt
Executable file
32
LICENSE.txt
Executable file
@@ -0,0 +1,32 @@
|
||||
|
||||
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
|
||||
版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
|
||||
All rights reserved。
|
||||
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
|
||||
|
||||
Apache Licence是著名的非盈利开源组织Apache采用的协议。
|
||||
该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
|
||||
允许代码修改,再作为开源或商业软件发布。需要满足
|
||||
的条件:
|
||||
1. 需要给代码的用户一份Apache Licence ;
|
||||
2. 如果你修改了代码,需要在被修改的文件中说明;
|
||||
3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
|
||||
带有原来代码中的协议,商标,专利声明和其他原来作者规
|
||||
定需要包含的说明;
|
||||
4. 如果再发布的产品中包含一个Notice文件,则在Notice文
|
||||
件中需要带有本协议内容。你可以在Notice中增加自己的
|
||||
许可,但不可以表现为对Apache Licence构成更改。
|
||||
具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
79
Schema/AdminAdminCreateUserRequest.json
Executable file
79
Schema/AdminAdminCreateUserRequest.json
Executable file
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"account": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 32
|
||||
},
|
||||
"passwd": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 6,
|
||||
"maxLength": 32
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 32
|
||||
},
|
||||
"department_id": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 32,
|
||||
"maxLength": 32
|
||||
},
|
||||
"status": {
|
||||
"type": "integer"
|
||||
},
|
||||
"certificate_type": {
|
||||
"type": "integer"
|
||||
},
|
||||
"certificate_num": {
|
||||
"type": "string"
|
||||
"minLength": 1,
|
||||
"maxLength": 32
|
||||
},
|
||||
"nickname": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 32
|
||||
},
|
||||
"wechat": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 1,
|
||||
"maxLength": 100
|
||||
},
|
||||
"email": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/i",
|
||||
"minLength": 5,
|
||||
"maxLength": 32
|
||||
},
|
||||
"qq": {
|
||||
"type": "integer"
|
||||
},
|
||||
"mobile": {
|
||||
"type": "string",
|
||||
"minLength": 8,
|
||||
"maxLength": 20
|
||||
},
|
||||
"role_id": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 32,
|
||||
"maxLength": 32
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
87
Schema/AdminAdminUpdateUserRequest.json
Executable file
87
Schema/AdminAdminUpdateUserRequest.json
Executable file
@@ -0,0 +1,87 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"passwd": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
},
|
||||
"department_id": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
},
|
||||
"certificate_type": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
},
|
||||
"certificate_num": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
},
|
||||
"nickname": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
},
|
||||
"wechat": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
},
|
||||
"qq": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
},
|
||||
"mobile": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
},
|
||||
"role_id": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Schema/AdminAuthAuthRequest.json
Executable file
24
Schema/AdminAuthAuthRequest.json
Executable file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"account": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "\/^[a-z0-9]+$\/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 15
|
||||
},
|
||||
"passwd": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "\/^[a-z0-9]+$\/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 32
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
416
Schema/AdminConfigSetAppConfigRequest.json
Executable file
416
Schema/AdminConfigSetAppConfigRequest.json
Executable file
@@ -0,0 +1,416 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"app_config": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"multi": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 99999999999
|
||||
},
|
||||
"create_time": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 99999999999
|
||||
},
|
||||
"update_time": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 99999999999
|
||||
},
|
||||
"show_card": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"copyright": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
},
|
||||
"mini_template_id": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
},
|
||||
"mini_app_name": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 30
|
||||
},
|
||||
"status": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"allow_create": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"create_text": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 100
|
||||
},
|
||||
"logo_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"logo_text": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 100
|
||||
},
|
||||
"logo_phone": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 20
|
||||
},
|
||||
"notice_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"notice_i": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 9999999999
|
||||
},
|
||||
"min_tmppid": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
},
|
||||
"order_overtime": {
|
||||
"type": "integer",
|
||||
"default": 1800,
|
||||
"minimum": 0,
|
||||
"maximum": 9999999999
|
||||
},
|
||||
"collage_overtime": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 9999999999
|
||||
},
|
||||
"force_phone": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"staff_extract": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"first_extract": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 3
|
||||
},
|
||||
"sec_extract": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"code": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 20
|
||||
},
|
||||
"corpid": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
},
|
||||
"corpsecret": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
},
|
||||
"agentid": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
},
|
||||
"wx_appid": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 100
|
||||
},
|
||||
"wx_tplid": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 100
|
||||
},
|
||||
"redis_pas": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 100
|
||||
},
|
||||
"cash_mini": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 9999999999
|
||||
},
|
||||
"admin_account": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 100
|
||||
},
|
||||
"plug_form": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"btn_consult": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 20
|
||||
},
|
||||
"btn_sale": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 20
|
||||
},
|
||||
"btn_code_err": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
},
|
||||
"btn_code_miss": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
},
|
||||
"preview_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 9999
|
||||
},
|
||||
"btn_talk": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 20
|
||||
},
|
||||
"receiving": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 9999999999
|
||||
},
|
||||
"ios_pay": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"android_pay": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"self_text": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
},
|
||||
"default_video": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
},
|
||||
"default_voice": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
},
|
||||
"card_type": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"order_pwd": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 40
|
||||
},
|
||||
"exchange_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"motto_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"default_voice_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"myshop_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"aliyun_sms_access_key_id": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 50
|
||||
},
|
||||
"aliyun_sms_access_key_secret": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 50
|
||||
},
|
||||
"default_shop_name": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 500
|
||||
},
|
||||
"default_shop_pic": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 500
|
||||
},
|
||||
"default_video_cover": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 500
|
||||
},
|
||||
"appoint_pic": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 500
|
||||
},
|
||||
"appoint_name": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 500
|
||||
},
|
||||
"click_copy_way": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"click_copy_show_img": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 500
|
||||
},
|
||||
"click_copy_content": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 500
|
||||
},
|
||||
"question_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"question_text": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
},
|
||||
"shop_version": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"shop_carousel_more": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 300
|
||||
},
|
||||
"exchange_btn": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 40
|
||||
},
|
||||
"my_shop_limit": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 9999999999
|
||||
},
|
||||
"autograph": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 99999999999
|
||||
},
|
||||
"signature": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 99999999999
|
||||
},
|
||||
"vr_tittle": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 50
|
||||
},
|
||||
"vr_cover": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 300
|
||||
},
|
||||
"vr_path": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 300
|
||||
},
|
||||
"vr_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"qr_avatar_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"coupon_pass": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 99999999999
|
||||
},
|
||||
"auto_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"auto_switch_way": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"job_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"appid": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 40
|
||||
},
|
||||
"app_secret": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 40
|
||||
},
|
||||
"chat_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"auth_switch": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
50
Schema/AdminConfigSetTabbarRequest.json
Executable file
50
Schema/AdminConfigSetTabbarRequest.json
Executable file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"minItems": 0,
|
||||
"maxItems": 20,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"menu_name": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 32
|
||||
},
|
||||
"is_show": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"pattern": "\/^[a-z0-9]+$\/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 20
|
||||
},
|
||||
"url": {
|
||||
"type": "string",
|
||||
"pattern": "\/^[a-z0-9]+$\/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 500
|
||||
},
|
||||
"url_out": {
|
||||
"type": "string",
|
||||
"pattern": "\/^[a-z0-9]+$\/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 500
|
||||
},
|
||||
"url_jump_way": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Schema/CustomerAdminAddQuestionnairRequest.json
Executable file
30
Schema/CustomerAdminAddQuestionnairRequest.json
Executable file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 100
|
||||
},
|
||||
"question": {
|
||||
"type": "array",
|
||||
"minItems": 0,
|
||||
"maxItems": 200,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Schema/CustomerAdminAddRelyTypeRequest.json
Executable file
21
Schema/CustomerAdminAddRelyTypeRequest.json
Executable file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 20
|
||||
},
|
||||
"top": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 999999999
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Schema/CustomerAdminAddReplyRequest.json
Executable file
27
Schema/CustomerAdminAddReplyRequest.json
Executable file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"content": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 100
|
||||
},
|
||||
"top": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 9999999999
|
||||
},
|
||||
"type": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 9999999999
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Schema/CustomerAdminSetQuestionnairConfigRequest.json
Executable file
21
Schema/CustomerAdminSetQuestionnairConfigRequest.json
Executable file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"question_switch": {
|
||||
"type": "integer",
|
||||
"default": 1,
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
},
|
||||
"question_text": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 200
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
54
Schema/CustomerAdminUpdateQuestionnairRequest.json
Executable file
54
Schema/CustomerAdminUpdateQuestionnairRequest.json
Executable file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"default": 1,
|
||||
"minimum": 1,
|
||||
"maximum": 99999999999
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 100
|
||||
},
|
||||
"status": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
},
|
||||
"question": {
|
||||
"type": "array",
|
||||
"minItems": 0,
|
||||
"maxItems": 200,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 99999999999
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 100
|
||||
},
|
||||
"status": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Schema/CustomerAdminUpdateRelyTypeRequest.json
Executable file
33
Schema/CustomerAdminUpdateRelyTypeRequest.json
Executable file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 9223372036854775807
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 20
|
||||
},
|
||||
"top": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 9999999999
|
||||
},
|
||||
"status": {
|
||||
"type": "integer",
|
||||
"default": 1,
|
||||
"minimum": 0,
|
||||
"maximum": 999
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Schema/CustomerAdminUpdateReplyRequest.json
Executable file
33
Schema/CustomerAdminUpdateReplyRequest.json
Executable file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 9999999999
|
||||
},
|
||||
"content": {
|
||||
"type": "string",
|
||||
"minLength": 0,
|
||||
"maxLength": 100
|
||||
},
|
||||
"top": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 9999999999
|
||||
},
|
||||
"type": {
|
||||
"type": "integer",
|
||||
"default": 0,
|
||||
"minimum": 0,
|
||||
"maximum": 9999999999
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
0
Schema/DynamicAdminoffUpdateContentRequest.json
Executable file
0
Schema/DynamicAdminoffUpdateContentRequest.json
Executable file
17
Schema/TestRequest.json
Executable file
17
Schema/TestRequest.json
Executable file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"account": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Schema/UserTestRequest.json
Executable file
17
Schema/UserTestRequest.json
Executable file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"account": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Schema/UserUserRequest.json
Executable file
17
Schema/UserUserRequest.json
Executable file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"user": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"account": {
|
||||
"type": "string",
|
||||
"format": "regex",
|
||||
"pattern": "/^[a-z0-9]+$/i",
|
||||
"minLength": 0,
|
||||
"maxLength": 9223372036854775807
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
274
app/AdminRest.php
Executable file
274
app/AdminRest.php
Executable file
@@ -0,0 +1,274 @@
|
||||
<?php
|
||||
declare ( strict_types = 1 );
|
||||
|
||||
namespace app;
|
||||
|
||||
use app\admin\service\UpdateService;
|
||||
use app\BaseController;
|
||||
use think\App;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
use think\Validate;
|
||||
use think\Response;
|
||||
use think\facade\Lang;
|
||||
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class AdminRest extends BaseController
|
||||
{
|
||||
//app名称
|
||||
public $_app = null;
|
||||
//控制器名称
|
||||
public $_controller = null;
|
||||
//执行方法名称
|
||||
public $_action = null;
|
||||
//method
|
||||
public $_method = 'GET';
|
||||
//query参数
|
||||
public $_param = [];
|
||||
//body参数
|
||||
public $_input = [];
|
||||
//头部
|
||||
public $_header = [];
|
||||
//头部token
|
||||
public $_token = null;
|
||||
//获取配置信息
|
||||
protected $_config = [];
|
||||
//语言信息
|
||||
public $_lang = 'zh-cn';
|
||||
//角色
|
||||
public $_role = 'guest';
|
||||
//host信息
|
||||
public $_host = null;
|
||||
//访问ip信息
|
||||
public $_ip = null;
|
||||
//用户信息
|
||||
public $_user = null;
|
||||
//唯一app标示
|
||||
public $_uniacid = '2';
|
||||
//定义检查中间件
|
||||
// protected $middleware = ['app\middleware\AppInit', 'app\middleware\CheckInput' ,'think\middleware\LoadLangPack' ,'app\middleware\AutoStatic','app\middleware\StaticHour', 'app\middleware\GetAuthConfig'];
|
||||
//判断是否是微擎
|
||||
public $_is_weiqin = false;
|
||||
/**
|
||||
* 小程序版本
|
||||
* 0 => 无限开版 其他 = 几开版
|
||||
* @var array
|
||||
*/
|
||||
protected $card_auth_version = 0;
|
||||
|
||||
/**
|
||||
* 可开通名片数量
|
||||
* 0 => 无限开版 其他 = 名片数量
|
||||
* @var array
|
||||
*/
|
||||
protected $card_auth_card = 0;
|
||||
|
||||
public function __construct ( App $app )
|
||||
{
|
||||
|
||||
|
||||
parent::__construct( $app );
|
||||
|
||||
//获取method
|
||||
$this->_method = $this->request->method( true );
|
||||
|
||||
$this->_is_weiqin = longbingIsWeiqin();
|
||||
//获取app名称
|
||||
$this->_app = $app->http->getName();
|
||||
//获取controller
|
||||
$this->_controller = $this->request->controller();
|
||||
//获取action名称
|
||||
$this->_action = $this->request->action();
|
||||
//获取param
|
||||
$this->_param = $this->request->param();
|
||||
//获取body参数
|
||||
$this->_input = json_decode( $this->request->getInput(), true );
|
||||
//获取头部信息
|
||||
$this->_header = $this->request->header();
|
||||
//获取请求host
|
||||
$this->_host = $this->_header[ 'host' ];
|
||||
//获取访问ip
|
||||
$this->_ip = $_SERVER[ 'REMOTE_ADDR' ];
|
||||
|
||||
if ( $this->_is_weiqin ) {
|
||||
|
||||
global $_GPC, $_W;
|
||||
|
||||
$this->_uniacid = $_W[ 'uniacid' ];
|
||||
|
||||
if (empty($_W['user']) || empty($_W[ 'uniacid' ])) {
|
||||
|
||||
echo json_encode(['code' => 401, 'error' => '请登录管理系统!']);
|
||||
exit;
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
//获取token 通过header获取token,如果不存在,则从param中获取。
|
||||
if ( !isset( $this->_header[ 'token' ] ) || empty($this->_header[ 'token' ]))
|
||||
{
|
||||
if(!isset( $this->_param[ 'token' ] ) || empty($this->_param[ 'token' ]))
|
||||
{
|
||||
//返回数数据
|
||||
echo json_encode(['code' => 401, 'error' => '请重新登录!']);
|
||||
exit;
|
||||
}else{
|
||||
$this->_header[ 'token' ] = $this->_param[ 'token' ];
|
||||
}
|
||||
}
|
||||
|
||||
//获取token
|
||||
$this->_token = $this->_header[ 'token' ] ;
|
||||
//语言
|
||||
if ( isset( $this->_header[ 'lang' ] ) ) $this->_lang = $this->_header[ 'lang' ];
|
||||
//获取用户信息
|
||||
$this->_user = getUserForToken( $this->_token );
|
||||
|
||||
if ($this->_user == null) {
|
||||
|
||||
echo json_encode(['code' => 401, 'error' => '请登录系统!']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->_uniacid = !empty( $this->_user ) && isset( $this->_user[ 'uniacid' ] ) ? $this->_user[ 'uniacid' ] : 2;
|
||||
}
|
||||
|
||||
landNotice($this->_uniacid);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//返回请求成功的数据
|
||||
public function success ( $data, $code = 200 )
|
||||
{
|
||||
$result[ 'data' ] = $data;
|
||||
$result[ 'code' ] = $code;
|
||||
$result[ 'sign' ] = null;
|
||||
//复杂的签名
|
||||
// if(isset($this->_user['keys'])){
|
||||
// $result['sign'] = rsa2CreateSign($this->_user['keys'] ,json_encode($data));
|
||||
// }
|
||||
//简单的签名
|
||||
if ( !empty( $this->_token ) ) $result[ 'sign' ] = createSimpleSign( $this->_token, is_string( $data ) ? $data : json_encode( $data ) );
|
||||
return $this->response( $result, 'json', $code );
|
||||
}
|
||||
|
||||
//返回错误数据
|
||||
public function error ( $msg, $code = 400 )
|
||||
{
|
||||
$result[ 'error' ] = Lang::get($msg);
|
||||
$result[ 'code' ] = $code;
|
||||
return $this->response( $result, 'json', 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出返回数据
|
||||
* @access protected
|
||||
* @param mixed $data 要返回的数据
|
||||
* @param String $type 返回类型 JSON XML
|
||||
* @param integer $code HTTP状态码
|
||||
* @return Response
|
||||
*/
|
||||
protected function response ( $data, $type = 'json', $code = 200 )
|
||||
{
|
||||
return Response::create( $data, $type )->code( $code );
|
||||
}
|
||||
|
||||
/**
|
||||
* REST 调用
|
||||
* @access public
|
||||
* @param string $method 方法名
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function _empty ( $method )
|
||||
{
|
||||
if ( method_exists( $this, $method . '_' . $this->method . '_' . $this->type ) ) {
|
||||
// RESTFul方法支持
|
||||
$fun = $method . '_' . $this->method . '_' . $this->type;
|
||||
}
|
||||
elseif ( $this->method == $this->restDefaultMethod && method_exists( $this, $method . '_' . $this->type ) ) {
|
||||
$fun = $method . '_' . $this->type;
|
||||
}
|
||||
elseif ( $this->type == $this->restDefaultType && method_exists( $this, $method . '_' . $this->method ) ) {
|
||||
$fun = $method . '_' . $this->method;
|
||||
}
|
||||
if ( isset( $fun ) ) {
|
||||
return App::invokeMethod( [
|
||||
$this,
|
||||
$fun
|
||||
]
|
||||
);
|
||||
}
|
||||
else {
|
||||
// 抛出异常
|
||||
throw new \Exception( 'error action :' . $method );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 获取支付信息
|
||||
*/
|
||||
public function payConfig (){
|
||||
$uniacid_id = !empty($uniacid)?$uniacid:$this->_uniacid;
|
||||
|
||||
$pay = Db::name('lbfarm_pay_config')->where(['uniacid'=>$uniacid_id])->find();
|
||||
|
||||
$config = Db::name( 'lbfarm_config')->where(['uniacid' => $uniacid_id])->find();
|
||||
|
||||
if(empty($pay[ 'mch_id' ])||empty($pay[ 'pay_key' ])){
|
||||
$this->errorMsg('未配置支付信息');
|
||||
}
|
||||
$setting[ 'payment' ][ 'merchant_id' ] = $pay[ 'mch_id' ];
|
||||
$setting[ 'payment' ][ 'key' ] = $pay[ 'pay_key' ];
|
||||
$setting[ 'payment' ][ 'cert_path' ] = $pay[ 'cert_path' ];
|
||||
$setting[ 'payment' ][ 'key_path' ] = $pay[ 'key_path' ];
|
||||
$setting[ 'app_id' ] = $config['appid'];
|
||||
$setting[ 'secret' ] = $config['appsecret'];
|
||||
Log::write($setting);
|
||||
return $setting;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* User: chenniang
|
||||
* Date: 2019-09-12 20:37
|
||||
* @param string $msg
|
||||
* @return void
|
||||
* descption:直接抛出异常
|
||||
*/
|
||||
protected function errorMsg($msg = '',$code = 400){
|
||||
$msg = Lang::get($msg);
|
||||
$this->results($msg,$code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回封装后的 API 数据到客户端
|
||||
* @access protected
|
||||
* @param mixed $msg 提示信息
|
||||
* @param mixed $data 要返回的数据
|
||||
* @param int $code 错误码,默认为0
|
||||
* @param string $type 输出类型,支持json/xml/jsonp
|
||||
* @param array $header 发送的 Header 信息
|
||||
* @return void
|
||||
* @throws HttpResponseException
|
||||
*/
|
||||
protected function results($msg, $code, array $header = [])
|
||||
{
|
||||
$result = [
|
||||
'error' => $msg,
|
||||
'code' => $code,
|
||||
];
|
||||
$response = Response::create($result, 'json', 200)->header($header);
|
||||
throw new HttpResponseException($response);
|
||||
}
|
||||
}
|
||||
325
app/AgentRest.php
Executable file
325
app/AgentRest.php
Executable file
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
declare ( strict_types = 1 );
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\App;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\facade\Db;
|
||||
use think\Response;
|
||||
use think\facade\Lang;
|
||||
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class AgentRest extends BaseController
|
||||
{
|
||||
//app名称
|
||||
public $_app = null;
|
||||
//控制器名称
|
||||
public $_controller = null;
|
||||
//执行方法名称
|
||||
public $_action = null;
|
||||
//method
|
||||
public $_method = 'GET';
|
||||
//query参数
|
||||
public $_param = [];
|
||||
//body参数
|
||||
public $_input = [];
|
||||
//头部
|
||||
public $_header = [];
|
||||
//头部token
|
||||
public $_token = null;
|
||||
//获取配置信息
|
||||
protected $_config = [];
|
||||
//语言信息
|
||||
public $_lang = 'zh-cn';
|
||||
//角色
|
||||
public $_role = 'guest';
|
||||
//host信息
|
||||
public $_host = null;
|
||||
//访问ip信息
|
||||
public $_ip = null;
|
||||
//用户信息
|
||||
public $_user = null;
|
||||
//唯一app标示
|
||||
public $_uniacid = '2';
|
||||
//定义检查中间件
|
||||
protected $middleware = ['app\middleware\AppInit', 'app\middleware\CheckInput' ,'think\middleware\LoadLangPack' ,'app\middleware\AutoStatic','app\middleware\StaticHour', 'app\middleware\GetAuthConfig'];
|
||||
//判断是否是微擎
|
||||
public $_is_weiqin = false;
|
||||
|
||||
public function __construct ( App $app )
|
||||
{
|
||||
parent::__construct( $app );
|
||||
|
||||
//获取头部信息
|
||||
$this->_header = $this->request->header();
|
||||
if (defined('IS_WEIQIN')) {
|
||||
global $_GPC, $_W;
|
||||
$this->_uniacid = $_W[ 'uniacid' ];
|
||||
$this->_user = $_W['user'];
|
||||
$role_map = [
|
||||
'founder' => 'admin',
|
||||
'operator' => 'guest',
|
||||
];
|
||||
$this->_role = $role_map[$_W['role']] ?? 'guest';
|
||||
|
||||
if (empty($this->_user)) {
|
||||
echo json_encode(['code' => 401, 'error' => '用户没有登录']);
|
||||
exit;
|
||||
}
|
||||
if (!$_W['isfounder']) {
|
||||
echo json_encode(['code' => 401, 'error' => '非超级管理员']);
|
||||
exit;
|
||||
}
|
||||
$this->_user['role_name']='admin';
|
||||
} else {
|
||||
//获取token
|
||||
if ( isset( $this->_header[ 'token' ] ) ) $this->_token = $this->_header[ 'token' ];
|
||||
|
||||
|
||||
//获取用户信息
|
||||
if ( !empty( $this->_token ) ) $this->_user = getUserForToken( $this->_token );
|
||||
//获取角色名称
|
||||
if ( !empty( $this->_user ) && isset( $this->_user[ 'role_name' ] ) ) $this->_role = $this->_user[ 'role_name' ];
|
||||
|
||||
|
||||
if ($this->_user == null) {
|
||||
echo json_encode(['code' => 401, 'error' => '用户没有登录']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->_uniacid = !empty( $this->_user ) && isset( $this->_user[ 'uniacid' ] ) ? $this->_user[ 'uniacid' ] : -1;
|
||||
|
||||
// if ($this->_user['role_name'] != 'admin') {
|
||||
// echo json_encode(['code' => 401, 'error' => '非超级管理员']);
|
||||
// exit;
|
||||
// }
|
||||
}
|
||||
|
||||
//获取app名称
|
||||
// $this->_app = $this->request->app();
|
||||
$this->_app = $app->http->getName();
|
||||
//获取controller
|
||||
$this->_controller = $this->request->controller();
|
||||
//获取action名称
|
||||
$this->_action = $this->request->action();
|
||||
|
||||
//获取method
|
||||
$this->_method = $this->request->method( true );
|
||||
//获取param
|
||||
$this->_param = $this->request->param();
|
||||
|
||||
//获取配置信息
|
||||
$this->_config = Db::name( 'longbing_card_config' )
|
||||
->where( [ 'uniacid' => $this->_uniacid ] )
|
||||
->find();
|
||||
|
||||
if(in_array($this->_method,['options','Options','OPTIONS'])){
|
||||
echo true;exit;
|
||||
}
|
||||
//获取body参数
|
||||
$this->_input = json_decode( $this->request->getInput(), true );
|
||||
|
||||
// //判断是否为json
|
||||
// if(!isset($this->request->header()['Content-Type'])) {
|
||||
// $this->_header['Content-Type'] = 'application/json';
|
||||
// $this->app->request->withHeader($this->_header);
|
||||
// }
|
||||
|
||||
//获取该应用下面所有的uniacid
|
||||
$this->_uniacid_arr = $this->getUniacid();
|
||||
//语言
|
||||
if ( isset( $this->_header[ 'lang' ] ) ) $this->_token = $this->_header[ 'lang' ];
|
||||
//获取请求host
|
||||
$this->_host = $this->_header[ 'host' ];
|
||||
//获取访问ip
|
||||
$this->_ip = $_SERVER[ 'REMOTE_ADDR' ];
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
//是否是微擎
|
||||
$this->_is_weiqin = longbingIsWeiqin();
|
||||
}
|
||||
|
||||
//返回请求成功的数据
|
||||
public function success ( $data, $code = 200 )
|
||||
{
|
||||
$result[ 'data' ] = $data;
|
||||
$result[ 'code' ] = $code;
|
||||
$result[ 'sign' ] = null;
|
||||
//复杂的签名
|
||||
// if(isset($this->_user['keys'])){
|
||||
// $result['sign'] = rsa2CreateSign($this->_user['keys'] ,json_encode($data));
|
||||
// }
|
||||
//简单的签名
|
||||
if ( !empty( $this->_token ) ) $result[ 'sign' ] = createSimpleSign( $this->_token, is_string( $data ) ? $data : json_encode( $data ) );
|
||||
return $this->response( $result, 'json', $code );
|
||||
}
|
||||
|
||||
//返回错误数据
|
||||
public function error ( $msg, $code = 400 )
|
||||
{
|
||||
// dd($this->request);die;
|
||||
// var_dump($this->_app ,$this->_controller ,$this->_action);die;
|
||||
$result[ 'error' ] = Lang::get($msg);
|
||||
$result[ 'code' ] = $code;
|
||||
return $this->response( $result, 'json', 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出返回数据
|
||||
* @access protected
|
||||
* @param mixed $data 要返回的数据
|
||||
* @param String $type 返回类型 JSON XML
|
||||
* @param integer $code HTTP状态码
|
||||
* @return Response
|
||||
*/
|
||||
protected function response ( $data, $type = 'json', $code = 200 )
|
||||
{
|
||||
return Response::create( $data, $type )->code( $code );
|
||||
}
|
||||
|
||||
/**
|
||||
* REST 调用
|
||||
* @access public
|
||||
* @param string $method 方法名
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function _empty ( $method )
|
||||
{
|
||||
if ( method_exists( $this, $method . '_' . $this->method . '_' . $this->type ) ) {
|
||||
// RESTFul方法支持
|
||||
$fun = $method . '_' . $this->method . '_' . $this->type;
|
||||
}
|
||||
elseif ( $this->method == $this->restDefaultMethod && method_exists( $this, $method . '_' . $this->type ) ) {
|
||||
$fun = $method . '_' . $this->type;
|
||||
}
|
||||
elseif ( $this->type == $this->restDefaultType && method_exists( $this, $method . '_' . $this->method ) ) {
|
||||
$fun = $method . '_' . $this->method;
|
||||
}
|
||||
if ( isset( $fun ) ) {
|
||||
return App::invokeMethod( [
|
||||
$this,
|
||||
$fun
|
||||
]
|
||||
);
|
||||
}
|
||||
else {
|
||||
// 抛出异常
|
||||
throw new \Exception( 'error action :' . $method );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Purpose: 获取formId
|
||||
*
|
||||
* @Author: zzf
|
||||
*
|
||||
* @Return: mixed 查询返回值(结果集对象)
|
||||
*/
|
||||
|
||||
public function getFormId ( $to_uid )
|
||||
{
|
||||
// 七天前开始的的时间戳
|
||||
// $beginTime = mktime( 0, 0, 0, date( 'm' ), date( 'd' ) - 6, date( 'Y' ) );
|
||||
$beginTime = strtotime(date('Y-m-d',time()))-86400*6;
|
||||
$formId = Db::name( 'longbing_card_formId' )
|
||||
->where( [ 'user_id' => $to_uid ] )
|
||||
->order( 'id desc' )
|
||||
->select();
|
||||
if ( empty( $formId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( $formId[ 0 ][ 'create_time' ] < $beginTime )
|
||||
{
|
||||
Db::name( 'longbing_card_formId' )
|
||||
->where( [ 'id' => $formId[ 0 ][ 'id' ] ] )
|
||||
->delete();
|
||||
$this->getFormId( $to_uid );
|
||||
}
|
||||
else
|
||||
{
|
||||
Db::name( 'longbing_card_formId' )
|
||||
->where( [ 'id' => $formId[ 0 ][ 'id' ] ] )
|
||||
->delete();
|
||||
return $formId[ 0 ][ 'formId' ];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 获取支付信息
|
||||
*/
|
||||
public function payConfig (){
|
||||
$pay = Db::name('longbing_card_config_pay')->where(['uniacid'=>$this->_uniacid])->find();
|
||||
if(empty($pay)){
|
||||
$this->errorMsg('no config of pay');
|
||||
}
|
||||
$setting[ 'payment' ][ 'merchant_id' ] = $pay[ 'mch_id' ];
|
||||
$setting[ 'payment' ][ 'key' ] = $pay[ 'pay_key' ];
|
||||
$setting[ 'payment' ][ 'cert_path' ] = $pay[ 'cert_path' ];
|
||||
$setting[ 'payment' ][ 'key_path' ] = $pay[ 'key_path' ];
|
||||
$setting[ 'app_id' ] = $this->_config['appid'];
|
||||
$setting[ 'secret' ] = $this->_config['app_secret'];
|
||||
return $setting;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* User: chenniang
|
||||
* Date: 2019-09-12 20:37
|
||||
* @param string $msg
|
||||
* @return void
|
||||
* descption:直接抛出异常
|
||||
*/
|
||||
protected function errorMsg($msg = '',$code = 400){
|
||||
$msg = Lang::get($msg);
|
||||
$this->results($msg,$code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回封装后的 API 数据到客户端
|
||||
* @access protected
|
||||
* @param mixed $msg 提示信息
|
||||
* @param mixed $data 要返回的数据
|
||||
* @param int $code 错误码,默认为0
|
||||
* @param string $type 输出类型,支持json/xml/jsonp
|
||||
* @param array $header 发送的 Header 信息
|
||||
* @return void
|
||||
* @throws HttpResponseException
|
||||
*/
|
||||
protected function results($msg, $code, array $header = [])
|
||||
{
|
||||
$result = [
|
||||
'error' => $msg,
|
||||
'code' => $code,
|
||||
];
|
||||
$response = Response::create($result, 'json', 200)->header($header);
|
||||
throw new HttpResponseException($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-06-05 09:13
|
||||
* @功能说明:获取微擎的uniacid(同应用下面的)array
|
||||
*/
|
||||
public function getUniacid(){
|
||||
|
||||
if(defined('IS_WEIQIN')){
|
||||
//模块名字
|
||||
$app_model_name = APP_MODEL_NAME;
|
||||
|
||||
$dis[] = ['modules','like','%'.$app_model_name.'%'];
|
||||
//获取该应用下面的所有uniacid
|
||||
$uniacid = Db::name('wxapp_versions')->where($dis)->column('uniacid');
|
||||
}else{
|
||||
|
||||
$uniacid = [$this->_user['uniacid']];
|
||||
}
|
||||
return $uniacid;
|
||||
}
|
||||
}
|
||||
573
app/ApiRest.php
Executable file
573
app/ApiRest.php
Executable file
@@ -0,0 +1,573 @@
|
||||
<?php
|
||||
declare ( strict_types = 1 );
|
||||
|
||||
namespace app;
|
||||
use app\BaseController;
|
||||
use app\card\model\User;
|
||||
use app\card\model\UserPhone;
|
||||
use app\farm\model\Farmer;
|
||||
use app\restaurant\model\Table;
|
||||
use app\shop\model\Cap;
|
||||
use longbingcore\tools\LongbingArr;
|
||||
use Qiniu\Auth;
|
||||
use think\App;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Request;
|
||||
use think\Validate;
|
||||
use think\Response;
|
||||
use think\facade\Db;
|
||||
use think\facade\Lang;
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class ApiRest extends BaseController
|
||||
{
|
||||
//app名称
|
||||
public $_app = null;
|
||||
//控制器名称
|
||||
public $_controller = null;
|
||||
//执行方法名称
|
||||
public $_action = null;
|
||||
//method
|
||||
public $_method = 'GET';
|
||||
//query参数
|
||||
public $_param = [];
|
||||
//body参数
|
||||
public $_input = [];
|
||||
//头部
|
||||
public $_header = [];
|
||||
//头部token
|
||||
public $_token = null;
|
||||
//语言信息
|
||||
public $_lang = 'zh-cn';
|
||||
//角色
|
||||
public $_role = 'guest';
|
||||
//host信息
|
||||
public $_host = null;
|
||||
//访问ip信息
|
||||
public $_ip = null;
|
||||
//用户信息
|
||||
public $_user = null;
|
||||
//获取用户id
|
||||
public $_user_id = null;
|
||||
//唯一app标示
|
||||
public $_uniacid = 1;
|
||||
//定义检查中间件
|
||||
// protected $middleware = [ 'app\middleware\CheckInput' ,'think\middleware\LoadLangPack' ,'app\middleware\GetAuthConfig' ,'app\middleware\AutoStatic','app\middleware\StaticHour'];
|
||||
|
||||
//获取配置信息
|
||||
protected $_config = [];
|
||||
|
||||
// 小程序登陆每个用户产生的唯一表示
|
||||
protected $autograph = '';
|
||||
|
||||
protected $uniacid = 0;
|
||||
|
||||
protected $is_app = 0;
|
||||
|
||||
protected $defaultImage = array(
|
||||
// 默认用户头像
|
||||
'avatar' => 'https://retail.xiaochengxucms.com/defaultAvatar.png',
|
||||
// 默认内容图片
|
||||
'image' => 'https://retail.xiaochengxucms.com/lbCardDefaultImage.png',
|
||||
);
|
||||
|
||||
protected $_is_weiqin = false ;
|
||||
|
||||
protected $check_url = "";
|
||||
|
||||
/**
|
||||
* 无需登录的方法,同时也就不需要鉴权了
|
||||
* @var array
|
||||
*/
|
||||
protected $noNeedLogin = ['getMonitorInfo','earTagTest'];
|
||||
|
||||
|
||||
public function __construct ( App $app )
|
||||
{
|
||||
|
||||
|
||||
parent::__construct( $app );
|
||||
|
||||
if(in_array($this->_method,['options','Options','OPTIONS'])){
|
||||
|
||||
echo true;exit;
|
||||
}
|
||||
|
||||
//获取param
|
||||
$this->_param = $this->request->param();
|
||||
//获取body参数
|
||||
$this->_input = json_decode( $this->request->getInput(), true );
|
||||
//获取头部信息
|
||||
$this->_header = $this->request->header();
|
||||
|
||||
|
||||
$this->is_app = !empty($this->_header['isapp'])?$this->_header['isapp']:0;
|
||||
|
||||
if ( defined( 'IS_WEIQIN' ) )
|
||||
{
|
||||
global $_GPC, $_W;
|
||||
$this->_uniacid = $_W[ 'uniacid' ];
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($this->_param[ 'i' ]))
|
||||
{
|
||||
$this->_uniacid = $this->_param[ 'i' ];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( defined( 'LONGBING_CARD_UNIACID' ) )
|
||||
{
|
||||
|
||||
define( 'LONGBING_CARD_UNIACID', $this->_uniacid );
|
||||
}
|
||||
|
||||
// $this->shareChangeData($this->_param);
|
||||
//获取autograph 小程序用户唯一标示
|
||||
if ( isset( $this->_header[ 'autograph' ] ) && $this->_header[ 'autograph' ])
|
||||
{
|
||||
$this->autograph = $this->_header['autograph'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$this->match($this->noNeedLogin)){
|
||||
|
||||
$this->errorMsg('need login',401);
|
||||
|
||||
}
|
||||
}
|
||||
//获取配置信息
|
||||
$this->_config = longbingGetAppConfig($this->_uniacid);
|
||||
//语言
|
||||
if ( isset( $this->_header[ 'lang' ] ) ) $this->_token = $this->_header[ 'lang' ];
|
||||
|
||||
if(!empty($this->autograph)&&!$this->match($this->noNeedLogin)){
|
||||
|
||||
$this->_user_id = $this->getUserId();
|
||||
|
||||
$this->_user = $this->getUserInfo();
|
||||
}
|
||||
|
||||
landNotice($this->_uniacid);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-08-21 17:43
|
||||
* @功能说明:
|
||||
*/
|
||||
public function shareChangeData($input){
|
||||
|
||||
$arr = [
|
||||
|
||||
'farm/app/Index/getYsToken',
|
||||
|
||||
'farm/app/Index/ysStartTurn',
|
||||
|
||||
'farm/app/Index/ysStopTurn',
|
||||
|
||||
'farm/app/Index/getMonitorInfo',
|
||||
|
||||
'farm/app/Index/index',
|
||||
|
||||
'farm/app/Index/couponList',
|
||||
|
||||
'farm/app/IndexClaim/claimCateList',
|
||||
|
||||
'farm/app/IndexLand/landList',
|
||||
|
||||
'farm/app/IndexClaim/claimBanner',
|
||||
|
||||
'farm/app/IndexClaim/claimCateList',
|
||||
|
||||
'farm/app/IndexClaim/claimList',
|
||||
|
||||
'farm/app/IndexGoods/goodsIndex',
|
||||
|
||||
'farm/app/IndexGoods/carInfo',
|
||||
|
||||
'farm/app/IndexGoods/goodsList',
|
||||
|
||||
'farm/app/IndexUser/userInfo',
|
||||
|
||||
'farm/app/IndexUser/index',
|
||||
|
||||
'farm/app/IndexUser/farmerInfo',
|
||||
|
||||
'farm/app/Index/configInfo',
|
||||
];
|
||||
|
||||
if(!empty($input['s'])&&in_array($input['s'],$arr)){
|
||||
|
||||
$input['s'] = trim(strrchr($input['s'], '/'),'/');
|
||||
|
||||
$this->noNeedLogin[] = $input['s'];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-07-09 12:00
|
||||
* @功能说明:检测方法传递
|
||||
*/
|
||||
public function match($arr){
|
||||
|
||||
|
||||
$arr = is_array($arr) ? $arr : explode(',', $arr);
|
||||
if (!$arr)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$arr = array_map('strtolower', $arr);
|
||||
// 是否存在
|
||||
if (in_array(strtolower($this->request->action()), $arr) || in_array('*', $arr))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// 没找到匹配
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//返回请求成功的数据
|
||||
public function success ( $data, $code = 200 )
|
||||
{
|
||||
$result[ 'data' ] = LongbingGetWxApiReturnData($data);
|
||||
$result[ 'code' ] = $code;
|
||||
$result[ 'sign' ] = null;
|
||||
//复杂的签名
|
||||
// if(isset($this->_user['keys'])){
|
||||
// $result['sign'] = rsa2CreateSign($this->_user['keys'] ,json_encode($data));
|
||||
// }
|
||||
//简单的签名
|
||||
if ( !empty( $this->_token ) ) $result[ 'sign' ] = createSimpleSign( $this->_token, is_string( $data ) ? $data : json_encode( $data ) );
|
||||
return $this->response( $result, 'json', $code );
|
||||
}
|
||||
|
||||
//返回错误数据
|
||||
public function error ( $msg, $code = 400 )
|
||||
{
|
||||
// $result[ 'error' ] = Lang::get($msg);
|
||||
// $result[ 'code' ] = $code;
|
||||
$result = $this->getErrorData($msg, $code);
|
||||
return $this->response( $result, 'json', 200 );
|
||||
}
|
||||
|
||||
public function getErrorData($msg, $code = 400)
|
||||
{
|
||||
$result[ 'error' ] = Lang::get($msg);
|
||||
$result[ 'code' ] = $code;
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* 输出返回数据
|
||||
* @access protected
|
||||
* @param mixed $data 要返回的数据
|
||||
* @param String $type 返回类型 JSON XML
|
||||
* @param integer $code HTTP状态码
|
||||
* @return Response
|
||||
*/
|
||||
protected function response ( $data, $type = 'json', $code = 200 )
|
||||
{
|
||||
return Response::create( $data, $type )->code( $code );
|
||||
}
|
||||
|
||||
/**
|
||||
* REST 调用
|
||||
* @access public
|
||||
* @param string $method 方法名
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function _empty ( $method )
|
||||
{
|
||||
if ( method_exists( $this, $method . '_' . $this->method . '_' . $this->type ) )
|
||||
{
|
||||
// RESTFul方法支持
|
||||
$fun = $method . '_' . $this->method . '_' . $this->type;
|
||||
}
|
||||
elseif ( $this->method == $this->restDefaultMethod && method_exists( $this, $method . '_' . $this->type ) )
|
||||
{
|
||||
$fun = $method . '_' . $this->type;
|
||||
}
|
||||
elseif ( $this->type == $this->restDefaultType && method_exists( $this, $method . '_' . $this->method ) )
|
||||
{
|
||||
$fun = $method . '_' . $this->method;
|
||||
}
|
||||
if ( isset( $fun ) )
|
||||
{
|
||||
return App::invokeMethod( [ $this, $fun ]
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 抛出异常
|
||||
throw new \Exception( 'error action :' . $method );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Purpose: 通过小程序端的用户标示获取用户信息
|
||||
*
|
||||
* @Author: zzf
|
||||
*
|
||||
* @Return: mixed 查询返回值(结果集对象)
|
||||
*/
|
||||
protected function getUserInfo ()
|
||||
{
|
||||
|
||||
$value = getCache($this->autograph, $this->_uniacid);
|
||||
|
||||
if(empty($value)){
|
||||
|
||||
$this->errorMsg('need login',401);
|
||||
}
|
||||
|
||||
if(empty($value['phone'])){
|
||||
|
||||
// $this->errorMsg('need phone',403);
|
||||
|
||||
}
|
||||
|
||||
$user_model = new \app\farm\model\User();
|
||||
|
||||
$value['balance'] = $user_model->where(['id'=>$value['id']])->value('balance');
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-19 15:22
|
||||
* @功能说明:获取当前的门店信息
|
||||
*/
|
||||
public function getStoreInfo($err=1){
|
||||
|
||||
$user_id = $this->getUserId();
|
||||
|
||||
$user_model = new \app\farm\model\User();
|
||||
|
||||
$cap_id = $user_model->where(['id'=>$user_id])->value('last_store_id');
|
||||
|
||||
$cap_info = [];
|
||||
|
||||
if(!empty($cap_id)){
|
||||
|
||||
$cap_model = new Farmer();
|
||||
|
||||
$dis = [
|
||||
|
||||
'id' => $cap_id,
|
||||
|
||||
'status' => 2,
|
||||
|
||||
'business_status' => 1,
|
||||
|
||||
'type' => 2,
|
||||
];
|
||||
|
||||
$cap_info = $cap_model->dataInfo($dis);
|
||||
}
|
||||
|
||||
if(empty($cap_info)&&$err==1){
|
||||
|
||||
// $this->errorMsg('请选择店铺',-407);
|
||||
|
||||
}
|
||||
|
||||
return $cap_info;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Purpose: 通过小程序端的用户标示获取用户id
|
||||
*
|
||||
* @Author: zzf
|
||||
*
|
||||
* @Return: mixed 查询返回值(结果集对象)
|
||||
*/
|
||||
protected function getUserId ()
|
||||
{
|
||||
|
||||
$value = getCache( $this->autograph, $this->_uniacid );
|
||||
|
||||
if($this->is_app==1){
|
||||
|
||||
|
||||
$user_model = new \app\farm\model\User();
|
||||
|
||||
$id = $user_model->where(['check'=>1])->value('id');
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
if ( ($value === false &&!$this->match($this->noNeedLogin)))
|
||||
{
|
||||
|
||||
$this->errorMsg('need login',401);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// if($this->match($this->noNeedLogin)&&empty($value)){
|
||||
//
|
||||
// $user_model = new \app\farm\model\User();
|
||||
//
|
||||
// $value =$user_model->dataInfo(['uniacid'=>$this->_uniacid,'check'=>1]);
|
||||
//
|
||||
// // setCache($this->autograph,$value,7200,$this->_uniacid);
|
||||
// }
|
||||
|
||||
// if ( (!empty($value['check']) &&!$this->match($this->noNeedLogin)))
|
||||
// {
|
||||
//
|
||||
// $this->errorMsg('need login',401);
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
return !empty($value[ 'id' ])?$value[ 'id' ]:0;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* 获取支付信息
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public function payConfig ($uniacid = '1',$is_app=7){
|
||||
|
||||
if($is_app==7){
|
||||
|
||||
$is_app = $this->is_app;
|
||||
}
|
||||
|
||||
$uniacid_id = !empty($uniacid)?$uniacid:$this->_uniacid;
|
||||
|
||||
$pay = Db::name('lbfarm_pay_config')->where(['uniacid'=>$uniacid_id])->find();
|
||||
|
||||
$config = Db::name( 'lbfarm_config')->where(['uniacid' => $uniacid_id])->find();
|
||||
|
||||
if(empty($pay[ 'mch_id' ])||empty($pay[ 'pay_key' ])){
|
||||
|
||||
// $this->errorMsg('未配置支付信息');
|
||||
}
|
||||
|
||||
$setting[ 'payment' ][ 'merchant_id' ] = $pay[ 'mch_id' ];
|
||||
|
||||
$setting[ 'payment' ][ 'key' ] = $pay[ 'pay_key' ];
|
||||
|
||||
$setting[ 'payment' ][ 'cert_path' ] = $pay[ 'cert_path' ];
|
||||
|
||||
$setting[ 'payment' ][ 'key_path' ] = $pay[ 'key_path' ];
|
||||
|
||||
$setting[ 'payment' ][ 'ali_appid' ] = $pay[ 'ali_appid' ];
|
||||
|
||||
$setting[ 'payment' ][ 'ali_privatekey' ] = $pay[ 'ali_privatekey' ];
|
||||
|
||||
$setting[ 'payment' ][ 'ali_publickey' ] = $pay[ 'ali_publickey' ];
|
||||
|
||||
if($is_app==0){
|
||||
|
||||
$setting[ 'app_id' ] = $config['appid'];
|
||||
|
||||
$setting[ 'secret' ] = $config['appsecret'];
|
||||
|
||||
}elseif($is_app==1){
|
||||
|
||||
$setting[ 'app_id' ] = $config['app_app_id'];
|
||||
|
||||
$setting[ 'secret' ] = $config['app_app_secret'];
|
||||
|
||||
}else{
|
||||
|
||||
$setting[ 'app_id' ] = $config['web_app_id'];
|
||||
|
||||
$setting[ 'secret' ] = $config['web_app_secret'];
|
||||
|
||||
}
|
||||
|
||||
$setting[ 'is_app' ]= $is_app;
|
||||
|
||||
return $setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Purpose: 获取formId
|
||||
*
|
||||
* @Author: zzf
|
||||
*
|
||||
* @Return: mixed 查询返回值(结果集对象)
|
||||
*/
|
||||
|
||||
public function getFormId ( $to_uid )
|
||||
{
|
||||
return [];
|
||||
// 七天前开始的的时间戳
|
||||
// $beginTime = mktime( 0, 0, 0, date( 'm' ), date( 'd' ) - 6, date( 'Y' ) );
|
||||
$beginTime = strtotime(date('Y-m-d',time()))-86400*6;
|
||||
$formId = Db::name( 'longbing_card_formId' )
|
||||
->where( [ 'user_id' => $to_uid ] )
|
||||
->order( 'id desc' )
|
||||
->select();
|
||||
if ( empty( $formId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( $formId[ 0 ][ 'create_time' ] < $beginTime )
|
||||
{
|
||||
Db::name( 'longbing_card_formId' )
|
||||
->where( [ 'id' => $formId[ 0 ][ 'id' ] ] )
|
||||
->delete();
|
||||
$this->getFormId( $to_uid );
|
||||
}
|
||||
else
|
||||
{
|
||||
Db::name( 'longbing_card_formId' )
|
||||
->where( [ 'id' => $formId[ 0 ][ 'id' ] ] )
|
||||
->delete();
|
||||
return $formId[ 0 ][ 'formId' ];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* User: chenniang
|
||||
* Date: 2019-09-12 20:37
|
||||
* @param string $msg
|
||||
* @return void
|
||||
* descption:直接抛出异常
|
||||
*/
|
||||
protected function errorMsg($msg = '',$code = 400){
|
||||
$msg = Lang::get($msg);
|
||||
$this->results($msg,$code);
|
||||
}
|
||||
|
||||
/**
|
||||
* User: chenniang
|
||||
* Date: 2019-09-12 20:42
|
||||
* @param $msg
|
||||
* @param int $code
|
||||
* @param array $header
|
||||
* @return void
|
||||
* descption:直接抛出状态
|
||||
*/
|
||||
protected function results($msg, $code, array $header = [])
|
||||
{
|
||||
$result = [
|
||||
'error' => $msg,
|
||||
'code' => $code,
|
||||
];
|
||||
$response = Response::create($result, 'json', 200)->header($header);
|
||||
throw new HttpResponseException($response);
|
||||
}
|
||||
}
|
||||
113
app/BaseController.php
Executable file
113
app/BaseController.php
Executable file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class BaseController
|
||||
{
|
||||
/**
|
||||
* Request实例
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
* @var \think\App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* 是否批量验证
|
||||
* @var bool
|
||||
*/
|
||||
protected $batchValidate = false;
|
||||
|
||||
/**
|
||||
* 控制器中间件
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
|
||||
longbing_check_install();
|
||||
|
||||
$this->app = $app;
|
||||
|
||||
$this->request = $this->app->request;
|
||||
|
||||
$this->_method = $this->request->method( true );
|
||||
|
||||
if(in_array($this->_method,['options','Options','OPTIONS'])){
|
||||
echo true;exit;
|
||||
}
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
|
||||
}
|
||||
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{}
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
* @access protected
|
||||
* @param array $data 数据
|
||||
* @param string|array $validate 验证器名或者验证规则数组
|
||||
* @param array $message 提示信息
|
||||
* @param bool $batch 是否批量验证
|
||||
* @return array|string|true
|
||||
* @throws ValidateException
|
||||
*/
|
||||
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
|
||||
{
|
||||
if (is_array($validate)) {
|
||||
$v = new Validate();
|
||||
$v->rule($validate);
|
||||
} else {
|
||||
if (strpos($validate, '.')) {
|
||||
// 支持场景
|
||||
list($validate, $scene) = explode('.', $validate);
|
||||
}
|
||||
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
||||
$v = new $class();
|
||||
if (!empty($scene)) {
|
||||
$v->scene($scene);
|
||||
}
|
||||
}
|
||||
|
||||
$v->message($message);
|
||||
|
||||
// 是否批量验证
|
||||
if ($batch || $this->batchValidate) {
|
||||
$v->batch(true);
|
||||
}
|
||||
|
||||
return $v->failException(true)->check($data);
|
||||
}
|
||||
|
||||
}
|
||||
80
app/BaseControllerV2.php
Executable file
80
app/BaseControllerV2.php
Executable file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class BaseControllerV2
|
||||
{
|
||||
|
||||
//唯一app标示
|
||||
public $_uniacid = 0;
|
||||
//query参数
|
||||
public $_param = [];
|
||||
//头部token
|
||||
public $_token = null;
|
||||
//
|
||||
public $_autograph = null;
|
||||
//请求对象 $request 兼容处理,即将废弃
|
||||
protected $request;
|
||||
protected $_request;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
|
||||
$this->request = $request;
|
||||
$this->_request = $this->request;
|
||||
$this->_param = $this->request->param();
|
||||
$this->_token = $this->request->header('token');
|
||||
$this->_autograph = $this->request->header('autograph');
|
||||
$this->_uniacid = intval( $this->request->param('i') ) ;
|
||||
$this->_uniacid = $this->_uniacid ? $this->_uniacid : intval( $this->request->param('uniacid') );
|
||||
|
||||
//兼容微擎新版本
|
||||
if(empty($this->_uniacid)&&longbingIsWeiqin()){
|
||||
|
||||
global $_GPC, $_W;
|
||||
$this->_uniacid = $_W[ 'uniacid' ];
|
||||
|
||||
}
|
||||
|
||||
//独立版拿不到uniacid
|
||||
if(empty($this->_uniacid)){
|
||||
|
||||
$user_info = getUserForToken($this->_token);
|
||||
|
||||
$this->_uniacid = $user_info['uniacid'];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户ID
|
||||
*
|
||||
* @return int
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/24 12:45
|
||||
*/
|
||||
protected function getUserId()
|
||||
{
|
||||
$value = getCache($this->_autograph, $this->_uniacid);
|
||||
|
||||
if ($value === false) {
|
||||
return 0;
|
||||
}
|
||||
return $value['id'];
|
||||
}
|
||||
}
|
||||
121
app/BaseModel.php
Executable file
121
app/BaseModel.php
Executable file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
namespace app;
|
||||
use think\Model;
|
||||
use think\facade\Db;
|
||||
class BaseModel extends Model {
|
||||
//设置数据库表名称
|
||||
protected $name = 'longbing';
|
||||
protected $type = [
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
'delete_time' => 'int',
|
||||
'deleted' => 'int'
|
||||
];
|
||||
//设置操作时间
|
||||
// public $time;
|
||||
// function __construct() {
|
||||
// parent::__construct();
|
||||
// $this->time = time();
|
||||
// }
|
||||
// //获取详情
|
||||
// public function getRow($filter) {
|
||||
// $filter['deleted'] = 0;
|
||||
// return $this->where($filter)->find();
|
||||
// }
|
||||
// //获取列表
|
||||
// public function listRow($filter ,$field = []) {
|
||||
// $filter['deleted'] = 0;
|
||||
// return $this->where($filter)
|
||||
// ->order('create_time', 'asc')
|
||||
// ->field($field)
|
||||
// ->select();
|
||||
// }
|
||||
// //创建
|
||||
// public function createRow($data) {
|
||||
// $data['create_time'] = time();
|
||||
// return $this->save($data);
|
||||
// }
|
||||
// //批量创建
|
||||
// public function createRows($datas) {
|
||||
// return $this->saveAll($datas);
|
||||
// }
|
||||
//
|
||||
// //更新
|
||||
// public function updateRow($filter ,$data) {
|
||||
// $filter['deleted'] = 0;
|
||||
// $data['update_time'] = time();
|
||||
// $result = $this->where($filter)->update($data);
|
||||
// return $result;
|
||||
// }
|
||||
// //删除
|
||||
// public function deleteRow($filter) {
|
||||
// $filter['deleted'] = 0;
|
||||
// return $this->updateRow($filter ,['delete_time' => time() ,'deleted' => 1]);
|
||||
// }
|
||||
|
||||
//获取详情
|
||||
public function getRow($filter)
|
||||
{
|
||||
$filter['deleted'] = 0;
|
||||
$result = $this
|
||||
->where($filter)
|
||||
->find();
|
||||
if(!empty($result)) $result = $result->toArray();
|
||||
return $result;
|
||||
}
|
||||
//获取列表
|
||||
public function listRow($filter)
|
||||
{
|
||||
$filter['deleted'] = 0;
|
||||
$result = $this
|
||||
->where($filter)
|
||||
->select();
|
||||
if(!empty($result)) $result = $result->toArray();
|
||||
return $result;
|
||||
}
|
||||
//创建
|
||||
public function createRow($data)
|
||||
{
|
||||
if(!empty($data['create_time'])){
|
||||
$data['create_time'] = time();
|
||||
}
|
||||
return $this->save($data);
|
||||
}
|
||||
//批量创建
|
||||
public function createRows($datas)
|
||||
{
|
||||
return $this->saveAll($datas);
|
||||
}
|
||||
public function upsave($filter ,$data)
|
||||
{
|
||||
$data['update_time'] = time();
|
||||
$result = $this->where($filter)->update($data);
|
||||
if(empty($result)) return false;
|
||||
return true;
|
||||
}
|
||||
//更新
|
||||
public function updateRow($filter ,$data)
|
||||
{
|
||||
$filter['deleted'] = 0;
|
||||
$data['update_time'] = time();
|
||||
$result = $this->where($filter)->update($data);
|
||||
if(empty($result)) return false;
|
||||
return true;
|
||||
}
|
||||
//删除
|
||||
public function deleteRow($filter)
|
||||
{
|
||||
$filter['deleted'] = 0;
|
||||
$result = $this->updateRow($filter ,['delete_time' => time() ,'deleted' => 1]);
|
||||
if(empty($result)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//真删除
|
||||
public function destroyRow($filter)
|
||||
{
|
||||
$result = $this->where($filter)->delete();
|
||||
if(empty($result)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
152
app/Common/ArticleFromUrl.php
Executable file
152
app/Common/ArticleFromUrl.php
Executable file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
/**
|
||||
* @Purpose: 获取文章内容
|
||||
*
|
||||
* @Param: string $url 公众号文章地址
|
||||
*
|
||||
* @Author: zzf
|
||||
*
|
||||
* @Return: mixed 查询返回值(结果集对象)
|
||||
*/
|
||||
|
||||
namespace app\Common;
|
||||
|
||||
use think\Exception;
|
||||
|
||||
class ArticleFromUrl
|
||||
{
|
||||
protected $html;
|
||||
|
||||
/**
|
||||
* @Purpose: 初始化方法
|
||||
*
|
||||
* @Param: string $url 公众号文章地址
|
||||
*
|
||||
* @Author: zzf
|
||||
*
|
||||
* @Return: mixed 查询返回值(结果集对象)
|
||||
*/
|
||||
public function __construct ( $url )
|
||||
{
|
||||
$this->html = file_get_contents( $url );
|
||||
}
|
||||
|
||||
/**
|
||||
* @Purpose: 获取文章内容
|
||||
*
|
||||
* @Author: zzf
|
||||
*
|
||||
* @Return: mixed 查询返回值(结果集对象)
|
||||
*/
|
||||
public function getArticle ()
|
||||
{
|
||||
$file = $this->html;
|
||||
|
||||
$file = str_replace( "data-src", "src", $file );
|
||||
$file = str_replace( "data-croporisrc", "src", $file );
|
||||
$file = str_replace( "preview.html", "player.html", $file );
|
||||
$file = str_replace( "display: inline-block;", "display: block;", $file );
|
||||
|
||||
$html = '';
|
||||
|
||||
$title = $this->get_between( $file, '<h2 class="rich_media_title" id="activity-name">', "</h2>" );
|
||||
|
||||
|
||||
if(strpos($file,'<div class="rich_media_content " id="js_content" style="visibility: hidden;">') !== false){
|
||||
$html_content = '<div class="rich_media_content " id="js_content" style="visibility: hidden;">';
|
||||
}else{
|
||||
$html_content = '<div class="rich_media_content " id="js_content">';
|
||||
|
||||
}
|
||||
// $html_content = str_replace('style="visibility: hidden;"','','<div class="rich_media_content " id="js_content" style="visibility: hidden;">');
|
||||
// dump($html_content);exit;
|
||||
// $content = $this->get_between( $file, '<div class="rich_media_content " id="js_content" ', "var first_sceen__time = (+new Date());" );
|
||||
$content = $this->get_between( $file, $html_content, "var first_sceen__time = (+new Date());" );
|
||||
$res = file_put_contents( 'tmp_article.txt', $content );
|
||||
if ( $res ) {
|
||||
$content = file( 'tmp_article.txt' );
|
||||
unset( $content[ count( $content ) - 1 ] );
|
||||
unset( $content[ count( $content ) - 1 ] );
|
||||
unset( $content[ count( $content ) - 1 ] );
|
||||
}
|
||||
$res = file_put_contents( 'tmp_article.txt', $content );
|
||||
if ( $res ) {
|
||||
$content = file_get_contents( 'tmp_article.txt' );
|
||||
}
|
||||
@unlink( 'tmp_article.txt' );
|
||||
|
||||
$html = $content;
|
||||
|
||||
$cover = '';
|
||||
|
||||
$title = trim( $title );
|
||||
$cover = trim( $cover );
|
||||
$html = trim( $html );
|
||||
return [ 'cover' => $cover, 'title' => $title, 'content' => $html ];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Purpose: php截取指定两个字符之间字符串
|
||||
*
|
||||
* @Param: string $input 字符串
|
||||
* @Param: int $start 开始截取位置
|
||||
* @Param: int $end 结束截取位置
|
||||
*
|
||||
* @Author: zzf
|
||||
*
|
||||
* @Return: mixed 查询返回值(结果集对象)
|
||||
*/
|
||||
protected function get_between ( $input, $start, $end )
|
||||
{
|
||||
|
||||
$substr = substr( $input, strlen( $start ) + strpos( $input, $start ), ( strlen( $input ) - strpos( $input, $end ) ) * ( -1 ) );
|
||||
// $substr = substr( $input, strpos( $input, $start ), ( strlen( $input ) - strpos( $input, $end ) ) * ( -1 ) );
|
||||
|
||||
return $substr;
|
||||
}
|
||||
|
||||
protected function getImageDown ( $str )
|
||||
{
|
||||
|
||||
if ( !is_dir( ATTACHMENT_ROOT . '/' . "images" ) ) {
|
||||
mkdir( ATTACHMENT_ROOT . '/' . "images" );
|
||||
}
|
||||
if ( !is_dir( ATTACHMENT_ROOT . '/' . "images/a_qr" ) ) {
|
||||
mkdir( ATTACHMENT_ROOT . '/' . "images/a_qr" );
|
||||
}
|
||||
if ( !is_dir( ATTACHMENT_ROOT . '/' . "images/a_image/" ) ) {
|
||||
mkdir( ATTACHMENT_ROOT . '/' . "images/a_image/" );
|
||||
}
|
||||
|
||||
$preg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';//匹配img标签的正则表达式
|
||||
|
||||
preg_match_all( $preg, $str, $allImg );//这里匹配所有的img
|
||||
|
||||
$allImg = $allImg[ 1 ];
|
||||
$allImgNot = array();
|
||||
$destination_folder = ATTACHMENT_ROOT . '/images' . "/a_image/";
|
||||
|
||||
foreach ( $allImg as $index2 => $item2 ) {
|
||||
$ftype = '.png';
|
||||
$res = getimagesize( $item2 );
|
||||
|
||||
if ( isset( $res[ 'mime' ] ) ) {
|
||||
if ( strpos( $res[ 'mime' ], 'gif' ) ) {
|
||||
$ftype = '.gif';
|
||||
}
|
||||
}
|
||||
$name = str_shuffle( time() . rand( 111111, 999999 ) ) . $ftype;
|
||||
$destination = $destination_folder . $name;
|
||||
$file = file_get_contents( $item2 );
|
||||
file_put_contents( $destination, $file );
|
||||
$image = 'images' . "/a_image/" . $name;
|
||||
array_push( $allImgNot, $image );
|
||||
$image = tomedia( $image );
|
||||
$allImg[ $index2 ] = $image;
|
||||
$str = str_replace( $item2, $image, $str );
|
||||
}
|
||||
return [ $str, $allImg, $allImgNot ];
|
||||
}
|
||||
|
||||
}
|
||||
43
app/Common/ComsumerApi.php
Executable file
43
app/Common/ComsumerApi.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*
|
||||
* mqp(RabbitMQ) - consumer 消费消息Api
|
||||
*
|
||||
*************************************/
|
||||
namespace app\Common;
|
||||
|
||||
use think\facade\Config;
|
||||
class ConsumerApi{
|
||||
public $conn;
|
||||
public $q_name;
|
||||
public $k_route;
|
||||
function __construct(){
|
||||
$conn_args = array(
|
||||
'host' => Config::get('rabbit.rabbit_host'),
|
||||
'port' => Config::get('rabbit.rabbit_port'),
|
||||
'login' => Config::get('rabbit.rabbit_login'),
|
||||
'password' => Config::get('rabbit.rabbit_passwd'),
|
||||
'vhost' => Config::get('rabbit.rabbit_vhost')
|
||||
);
|
||||
$this->e_name = Config::get('rabbit.rabbit_exchange_name');
|
||||
$this->q_name = Config::get('rabbit.rabbit_query_name');
|
||||
$this->k_route = Config::get('rabbit.rabbit_key');
|
||||
$this->conn = new AMQPConnection($conn_args);
|
||||
if (!$this->conn->connect()) {
|
||||
die("Cannot connect to the broker!\n");
|
||||
}
|
||||
}
|
||||
public function consumerMessage(){
|
||||
$channel = new AMQPChannel($this->conn);
|
||||
$q = new AMQPQueue($channel);
|
||||
$q->setName($this->q_name);
|
||||
$q->setFlags(AMQP_DURABLE);
|
||||
while($a=$q->declare())
|
||||
{
|
||||
$gets = $q->get(AMQP_AUTOACK);
|
||||
$messages[] = $gets->getBody();
|
||||
}
|
||||
|
||||
$this->conn->disconnect();
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
641
app/Common/JsonSchema.php
Executable file
641
app/Common/JsonSchema.php
Executable file
@@ -0,0 +1,641 @@
|
||||
<?php
|
||||
/**
|
||||
* JSON Schema generate/validate
|
||||
*
|
||||
*/
|
||||
namespace app\Common;
|
||||
class JsonSchema {
|
||||
|
||||
/**
|
||||
* JSON
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $json;
|
||||
/**
|
||||
* Last error
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $errors;
|
||||
/**
|
||||
* Extend types
|
||||
*
|
||||
* @var map
|
||||
*/
|
||||
private $complexTypes;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $json
|
||||
*/
|
||||
function __construct($json) {
|
||||
$this -> errors = array();
|
||||
$this -> complexTypes = array();
|
||||
$this -> json = json_decode($json);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate JSON Schema
|
||||
*
|
||||
* @return string JSON Schema
|
||||
*/
|
||||
public function getSchema() {
|
||||
$schema = null;
|
||||
$schema = $this -> genByType($this -> json);
|
||||
return json_encode($schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate JSON Schema by type
|
||||
* @param mixed $value
|
||||
* @return object
|
||||
*/
|
||||
private function genByType($value) {
|
||||
$type = gettype($value);
|
||||
$schema = array();
|
||||
switch ($type) {
|
||||
case 'boolean' :
|
||||
$schema['type'] = 'boolean';
|
||||
$schema['default'] = false;
|
||||
break;
|
||||
case 'integer' :
|
||||
$schema['type'] = 'integer';
|
||||
$schema['default'] = 0;
|
||||
$schema['minimum'] = 0;
|
||||
$schema['maximum'] = PHP_INT_MAX;
|
||||
$schema['exclusiveMinimum'] = 0;
|
||||
$schema['exclusiveMaximum'] = PHP_INT_MAX;
|
||||
break;
|
||||
case 'double' :
|
||||
$schema['type'] = 'number';
|
||||
$schema['default'] = 0;
|
||||
$schema['minimum'] = 0;
|
||||
$schema['maximum'] = PHP_INT_MAX;
|
||||
$schema['exclusiveMinimum'] = 0;
|
||||
$schema['exclusiveMaximum'] = PHP_INT_MAX;
|
||||
break;
|
||||
case 'string' :
|
||||
$schema['type'] = 'string';
|
||||
$schema['format'] = 'regex';
|
||||
$schema['pattern'] = '/^[a-z0-9]+$/i';
|
||||
$schema['minLength'] = 0;
|
||||
$schema['maxLength'] = PHP_INT_MAX;
|
||||
break;
|
||||
case 'array' :
|
||||
$schema['type'] = 'array';
|
||||
$schema['minItems'] = 0;
|
||||
$schema['maxItems'] = 20;
|
||||
$items = array();
|
||||
foreach ($value as $value) {
|
||||
$items = $this -> genByType($value);
|
||||
break;
|
||||
}
|
||||
$schema['items'] = $items;
|
||||
break;
|
||||
case 'object' :
|
||||
$schema['type'] = 'object';
|
||||
$items = array();
|
||||
$value = get_object_vars($value);
|
||||
foreach ($value as $key => $value) {
|
||||
$items[$key] = $this -> genByType($value);
|
||||
}
|
||||
$schema['properties'] = $items;
|
||||
break;
|
||||
case 'null' :
|
||||
// any in union types
|
||||
$schema['type'] = 'null';
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set type schema
|
||||
* @param string $typeSchema
|
||||
*/
|
||||
public function addType($typeSchema) {
|
||||
if (empty($typeSchema)) {
|
||||
return;
|
||||
}
|
||||
$typeSchema = json_decode($typeSchema, true);
|
||||
if (is_array($typeSchema) && isset($typeSchema['id'])) {
|
||||
$this -> complexTypes[$typeSchema['id']] = $typeSchema;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type schema
|
||||
*
|
||||
* @param string ref
|
||||
* @return string schema
|
||||
*/
|
||||
private function getType($ref) {
|
||||
if (isset($this -> complexTypes[$ref])) {
|
||||
return $this -> complexTypes[$ref];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate JSON
|
||||
*
|
||||
* @param string $schema JSON Schema
|
||||
* @return boolean
|
||||
*/
|
||||
public function validate($schema) {
|
||||
$isVali = false;
|
||||
do {
|
||||
$schema = json_decode($schema, true);
|
||||
if (!is_array($schema) || !isset($schema['type'])) {
|
||||
$this -> addError('100', 'schema parse error. (PHP 5 >= 5.3.0) see json_last_error(void).');
|
||||
break;
|
||||
}
|
||||
|
||||
$isVali = $this -> checkByType($this -> json, $key = null, $schema);
|
||||
} while (false);
|
||||
return $isVali;
|
||||
}
|
||||
|
||||
/**
|
||||
* check type: string
|
||||
* http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.1
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $schema
|
||||
*/
|
||||
private function checkString($value, $key, $schema) {
|
||||
// string
|
||||
$isVali = false;
|
||||
do {
|
||||
if (!is_string($value) && !is_numeric($value)) {
|
||||
$this -> addError('101', $key . ' : ' . json_encode($value) . ' is not a string.', $key);
|
||||
break;
|
||||
}
|
||||
$len = strlen(trim($value));
|
||||
if (isset($schema['minLength'])) {
|
||||
if ($schema['minLength'] > $len) {
|
||||
$this -> addError('102', $key . ': ' . json_encode($value) . ' is too short.', $key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isset($schema['maxLength'])) {
|
||||
if ($schema['maxLength'] < $len) {
|
||||
$this -> addError('102', $key . ': ' . json_encode($value) . ' is too long.', $key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($schema['format'])) {
|
||||
switch ($schema['format']) {
|
||||
|
||||
case 'date-time' :
|
||||
/**
|
||||
* date-time This SHOULD be a date in ISO 8601 format of YYYY-MM-
|
||||
* DDThh:mm:ssZ in UTC time. This is the recommended form of date/
|
||||
* timestamp.
|
||||
*/
|
||||
break;
|
||||
case 'date' :
|
||||
/**
|
||||
* date This SHOULD be a date in the format of YYYY-MM-DD. It is
|
||||
* recommended that you use the"date-time"format instead of"date"
|
||||
* unless you need to transfer only the date part.
|
||||
*/
|
||||
break;
|
||||
case 'time' :
|
||||
/**
|
||||
* time This SHOULD be a time in the format of hh:mm:ss. It is
|
||||
* recommended that you use the"date-time"format instead of"time"
|
||||
* unless you need to transfer only the time part.
|
||||
*/
|
||||
break;
|
||||
case 'utc-millisec' :
|
||||
/**
|
||||
* utc-millisec This SHOULD be the difference, measured in
|
||||
* milliseconds, between the specified time and midnight, 00:00 of
|
||||
* January 1, 1970 UTC. The value SHOULD be a number (integer or
|
||||
* float).
|
||||
*/
|
||||
break;
|
||||
case 'regex' :
|
||||
/**
|
||||
* regex A regular expression, following the regular expression
|
||||
* specification from ECMA 262/Perl 5.
|
||||
*/
|
||||
if (isset($schema['pattern'])) {
|
||||
$pattern = $schema['pattern'];
|
||||
|
||||
if (preg_match($pattern, $value)) {
|
||||
$isVali = true;
|
||||
} else {
|
||||
$this -> addError('101', $key . ':' . $value . ' does not match ' . $pattern, $key);
|
||||
}
|
||||
} else {
|
||||
$this -> addError('101', 'format-regex: pattern is undefined.', $key);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'color' :
|
||||
/**
|
||||
* color This is a CSS color (like"#FF0000"or"red"), based on CSS
|
||||
* 2.1 [W3C.CR-CSS21-20070719].
|
||||
*/
|
||||
break;
|
||||
case 'style' :
|
||||
/**
|
||||
* style This is a CSS style definition (like"color: red; background-
|
||||
* color:#FFF"), based on CSS 2.1 [W3C.CR-CSS21-20070719].
|
||||
*/
|
||||
break;
|
||||
case 'phone' :
|
||||
/**
|
||||
* phone This SHOULD be a phone number (format MAY follow E.123).
|
||||
* http://en.wikipedia.org/wiki/E.123
|
||||
*/
|
||||
if (preg_match("/^((0?[0-9]{2}) d{3,4}s?d{4}|+d{2} d{2} d{3,4}s?d{4})$/", $value)) {
|
||||
$isVali = true;
|
||||
} else {
|
||||
$this -> addError('101', $key . ': ' . $value . ' is not a phone number.', $key);
|
||||
}
|
||||
break;
|
||||
case 'uri' :
|
||||
/**
|
||||
* uri This value SHOULD be a URI..
|
||||
*/
|
||||
if (filter_var($value, FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED)) {
|
||||
$isVali = true;
|
||||
} else {
|
||||
$this -> addError('101', $key . ': ' . $value . ' is not a URI.', $key);
|
||||
}
|
||||
break;
|
||||
case 'email' :
|
||||
/**
|
||||
* email This SHOULD be an email address.
|
||||
*/
|
||||
if (filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
||||
$isVali = true;
|
||||
} else {
|
||||
$this -> addError('101', $key . ': ' . json_encode($value) . ' is not a email.', $key);
|
||||
}
|
||||
break;
|
||||
case 'ip-address' :
|
||||
/**
|
||||
* ip-address This SHOULD be an ip version 4 address.
|
||||
*/
|
||||
if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
||||
$isVali = true;
|
||||
} else {
|
||||
$this -> addError('101', $key . ': ' . json_encode($value) . ' is not a ipv4 address.', $key);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'ipv6' :
|
||||
/**
|
||||
* ipv6 This SHOULD be an ip version 6 address.
|
||||
*/
|
||||
if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
$isVali = true;
|
||||
} else {
|
||||
$this -> addError('101', $key . ': ' . json_encode($value) . ' is not a ipv6 address.', $key);
|
||||
}
|
||||
break;
|
||||
case 'host-name' :
|
||||
/**
|
||||
* host-name This SHOULD be a host-name.
|
||||
*/
|
||||
break;
|
||||
|
||||
default :
|
||||
$this -> addError('101', $schema['format'] . ' is undefined.', $key);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$isVali = true;
|
||||
} while (false);
|
||||
return $isVali;
|
||||
}
|
||||
|
||||
/**
|
||||
* check type: integer/double
|
||||
*
|
||||
* @param number $value
|
||||
* @param array $schema
|
||||
* @return boolean
|
||||
*/
|
||||
private function checkNumber($value, $key, $schema = null) {
|
||||
// number
|
||||
$isVali = false;
|
||||
do {
|
||||
|
||||
if (!is_numeric($value)) {
|
||||
$this -> addError($value . ' is not a number.');
|
||||
break;
|
||||
}
|
||||
if (isset($schema['minimum'])) {
|
||||
if ($schema['minimum'] > $value) {
|
||||
$this -> addError('103', $key . ':' . json_encode($value) . ' is less than ' . $schema['minimum'], $key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isset($schema['maximum'])) {
|
||||
if ($schema['maximum'] < $value) {
|
||||
$this -> addError('103', $key . ':' . json_encode($value) . ' is bigger than ' . $schema['maximum'], $key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isset($schema['exclusiveMinimum'])) {
|
||||
if ($schema['exclusiveMinimum'] >= $value) {
|
||||
$this -> addError('103', $key . ':' . json_encode($value) . ' is less or than ' . $schema['exclusiveMinimum'] . ' or equal', $key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isset($schema['exclusiveMaximum'])) {
|
||||
if ($schema['exclusiveMaximum'] <= $value) {
|
||||
$this -> addError('103', $key . ':' . $value . ' is bigger than ' . $schema['exclusiveMaximum'] . ' or equal', $key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$isVali = true;
|
||||
} while (false);
|
||||
|
||||
return $isVali;
|
||||
}
|
||||
|
||||
/**
|
||||
* check type: integer
|
||||
*
|
||||
* @param integer $value
|
||||
* @param array $schema
|
||||
* @return boolean
|
||||
*/
|
||||
private function checkInteger($value, $key, $schema) {
|
||||
// integer
|
||||
if (!is_integer($value)) {
|
||||
$this -> addError('101', $key . ': ' . $value . ' is not a integer', $key);
|
||||
return false;
|
||||
}
|
||||
return $this -> checkNumber($value, $schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* check type: boolean
|
||||
*
|
||||
* @param boolean $value
|
||||
* @param array $schema
|
||||
* @return boolean
|
||||
*/
|
||||
private function checkBoolean($value, $key, $schema) {
|
||||
// boolean
|
||||
if (!is_bool($value)) {
|
||||
$this -> addError('101', $key . ': ' . json_encode($value) . ' is not a boolean.', $key);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* check type: object
|
||||
*
|
||||
* @param object $valueProp
|
||||
* @param array $schema
|
||||
* @return boolean
|
||||
*/
|
||||
private function checkObject($value, $key = null, $schema = null) {
|
||||
// object
|
||||
$isVali = false;
|
||||
|
||||
do {
|
||||
if (!is_object($value)) {
|
||||
$this -> addError('101', $key . ': ' . json_encode($value) . ' is not an object.', $key);
|
||||
break;
|
||||
}
|
||||
if (isset($schema['properties']) && !empty($schema['properties'])) {
|
||||
$schemaProp = $schema['properties'];
|
||||
// 正确的required应该与properties同级
|
||||
if (!isset($schema['required']))
|
||||
$schema['required'] = null;
|
||||
if (!isset($schemaProp['required']))
|
||||
$schemaProp['required'] = null;
|
||||
$requireds = $schemaProp['required'] ? : $schema['required'];
|
||||
$valueProp = get_object_vars($value);
|
||||
$valueKeys = array_keys($valueProp);
|
||||
$schemaKeys = array_keys($schemaProp);
|
||||
$diffKeys = array_diff($valueKeys, $schemaKeys);
|
||||
if (!empty($diffKeys)) {
|
||||
foreach ($diffKeys as $key) {
|
||||
// property not defined / not optional
|
||||
|
||||
if (!isset($schemaProp[$key]) || !isset($schemaProp[$key]['optional']) || !$schemaProp[$key]['optional']) {
|
||||
|
||||
$this -> addError('101', $key . ': ' . json_encode($value) . ' is not exist,And its not a optional property.', $key);
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_array($requireds)) {
|
||||
if (is_object($value)) {
|
||||
foreach ($value as $key => $v) {
|
||||
if (isset($v)) {
|
||||
} else {
|
||||
if (in_array($key, $requireds)) {
|
||||
$this -> addError('101', $key . ': ' . json_encode($value) . ' is not exist,And its not a optional property.', $key);
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
$key_arr[] = $key;
|
||||
}
|
||||
foreach ($requireds as $reval) {
|
||||
if (!in_array($reval, $key_arr)) {
|
||||
$this -> addError('101', $reval . ' is not exist,And its not a optional property.', $reval);
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($schemaProp as $key => $sch) {
|
||||
if (!isset($valueProp[$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$this -> checkByType($valueProp[$key], $key, $sch)) {
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
$isVali = true;
|
||||
} while (false);
|
||||
return $isVali;
|
||||
}
|
||||
|
||||
/**
|
||||
* check type: array
|
||||
*
|
||||
* @param array $value
|
||||
* @param array $schema
|
||||
* @return boolean
|
||||
*/
|
||||
private function checkArray($value, $key, $schema) {
|
||||
$isVali = false;
|
||||
do {
|
||||
if (!is_array($value)) {
|
||||
$this -> addError('101', $key . ' : ' . json_encode($value) . ' is not an array.', $key);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isset($schema['items'])) {
|
||||
$this -> addError('101', $this -> error('schema: items schema is undefined.'), $key);
|
||||
break;
|
||||
}
|
||||
$size = count($value);
|
||||
if (isset($schema['minItems'])) {
|
||||
if ($schema['minItems'] > $size) {
|
||||
$this -> addError('102', $this -> error('array size: ') . $size . $this -> error(' is less than ') . $schema['minItems'] . '.', $key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isset($schema['maxItems'])) {
|
||||
if ($schema['maxItems'] < $size) {
|
||||
$this -> addError('102', $this -> error('array size: ') . $size . $this -> error(' is bigger than ') . $schema['maxItems'] . '.', $key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($value as $val) {
|
||||
if (!$this -> checkByType($val, '', $schema['items'])) {
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
|
||||
$isVali = true;
|
||||
} while (false);
|
||||
return $isVali;
|
||||
}
|
||||
|
||||
/**
|
||||
* check value based on type
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param array $schema
|
||||
* @return boolean
|
||||
*/
|
||||
private function checkByType($value, $key = null, $schema) {
|
||||
|
||||
$isVali = false;
|
||||
if ($schema && isset($schema['type'])) {
|
||||
// union types 联合类型
|
||||
if (is_array($schema['type'])) {
|
||||
$types = $schema['type'];
|
||||
foreach ($types as $type) {
|
||||
|
||||
$schema['type'] = $type;
|
||||
$isVali = $this -> checkByType($value, $key, $schema);
|
||||
|
||||
if ($isVali) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$type = $schema['type'];
|
||||
|
||||
switch ($type) {
|
||||
case 'boolean' :
|
||||
$isVali = $this -> checkBoolean($value, $key, $schema);
|
||||
break;
|
||||
case 'integer' :
|
||||
if (preg_match("/^[0-9]+$/", $value)) {
|
||||
$value = intval($value);
|
||||
}
|
||||
$isVali = $this -> checkInteger($value, $key, $schema);
|
||||
break;
|
||||
case 'number' :
|
||||
$isVali = $this -> checkNumber($value, $key, $schema);
|
||||
break;
|
||||
case 'string' :
|
||||
$isVali = $this -> checkString($value, $key, $schema);
|
||||
break;
|
||||
case 'array' :
|
||||
$isVali = $this -> checkArray($value, $key, $schema);
|
||||
break;
|
||||
case 'object' :
|
||||
$isVali = $this -> checkObject($value, $key, $schema);
|
||||
|
||||
break;
|
||||
case 'enum' :
|
||||
$isVali = is_null($value);
|
||||
break;
|
||||
case 'null' :
|
||||
$isVali = is_null($value);
|
||||
break;
|
||||
case 'any' :
|
||||
$isVali = true;
|
||||
break;
|
||||
default :
|
||||
$this -> addError('101', $this -> error('type_schema : ') . $value . $this -> error(' is undefined.'), $key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($schema['$ref'])) {
|
||||
$isVali = $this -> checkByType($value, $key, $this -> getType($schema['$ref']));
|
||||
}
|
||||
return $isVali;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get errors
|
||||
*
|
||||
* @return array errors
|
||||
*/
|
||||
public function getErrors() {
|
||||
|
||||
return json_encode(['error' => $this -> errors], true);
|
||||
}
|
||||
/**
|
||||
* add error message
|
||||
* @param string $msg
|
||||
*/
|
||||
protected function addError($code = null, $msg = null, $key = null) {
|
||||
$this -> errors = array('contents' => $this -> error('validate fail'), 'return_code' => '1100', 'message' => $this -> error($key) . $this -> error(': the format is not correct.'), 'timestamp' => time());
|
||||
}
|
||||
|
||||
/**
|
||||
* 报错信息
|
||||
*/
|
||||
protected function error($message) {
|
||||
// 入口已经处理了语种,这里再加没有意义
|
||||
// $header = getallheaders();
|
||||
// //获取头部信息,得到需要返回的语言
|
||||
// $lan = $header['lan'];
|
||||
// if($lan == 'zh_CN'){
|
||||
// putenv('LANG=zh_CN');
|
||||
// setlocale(LC_ALL, 'zh_CN'); //指定要用的语系,如:en_US、zh_CN、zh_TW
|
||||
// }elseif ($lan == 'zh_TW'){
|
||||
// putenv('LANG=zh_TW');
|
||||
// setlocale(LC_ALL, 'zh_TW'); //指定要用的语系,如:en_US、zh_CN、zh_TW
|
||||
// }elseif ($lan == 'en_US') {
|
||||
// putenv('LANG=en_US');
|
||||
// setlocale(LC_ALL, 'en_US'); //指定要用的语系,如:en_US、zh_CN、zh_TW
|
||||
// }
|
||||
// if ($lan == null) {
|
||||
// putenv('LANG=en_US');
|
||||
// setlocale(LC_ALL, 'en_US');
|
||||
// }
|
||||
// //默认开启zh_CN
|
||||
// $locale = "zh_CN.utf8";
|
||||
// setlocale(LC_ALL, $locale);
|
||||
// //设置翻译文本域,下面的代码就会让程序去locale/zh_CN/LC_MESSAGES/default.mo去寻找翻译文件
|
||||
// bindtextdomain("Education", $_SERVER['DOCUMENT_ROOT'].'locale');
|
||||
// textdomain("Education");
|
||||
$message = _($message);
|
||||
return $message;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
72
app/Common/LongbingCurl.php
Executable file
72
app/Common/LongbingCurl.php
Executable file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
namespace app\Common;
|
||||
class LongbingCurl{
|
||||
protected $_errno;
|
||||
protected $_error;
|
||||
public function __construct(){
|
||||
|
||||
}
|
||||
/**
|
||||
* 获取错误信息
|
||||
* @return object | null
|
||||
*/
|
||||
public function getError() {
|
||||
return $this->_error ? (object) [
|
||||
'errno' => $this->_errno,
|
||||
'error' => $this->_error
|
||||
] : NULL;
|
||||
}
|
||||
//基础请求
|
||||
public function crulGetData($url, $post, $method, $header=1){
|
||||
$this->_errno = NULL;
|
||||
$this->_error = NULL;
|
||||
$ch = curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
if($post != NULL)
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
|
||||
curl_setopt($ch, CURLOPT_AUTOREFERER,true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
|
||||
|
||||
if($header)
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Content-type: application/json',
|
||||
)
|
||||
);
|
||||
$result = curl_exec($ch);
|
||||
return $result;
|
||||
}
|
||||
//get请求
|
||||
public function curlGet($url,$post=NULL){
|
||||
$result = $this->crulGetData($url,$post,'GET');
|
||||
return $result;
|
||||
}
|
||||
//post请求
|
||||
public function curlPost($url,$post=NULL){
|
||||
$result = $this->crulGetData($url,$post,'POST');
|
||||
return $result;
|
||||
}
|
||||
//patch请求
|
||||
public function curlPatch($url,$post){
|
||||
$result = $this->crulGetData($url,$post,'PATCH');
|
||||
return $result;
|
||||
}
|
||||
//put请求
|
||||
public function curlPut($url,$post){
|
||||
$result = $this->crulGetData($url,$post,'PUT');
|
||||
return $result;
|
||||
}
|
||||
//deletd请求
|
||||
public function curlDelete($url,$post){
|
||||
$result = $this->crulGetData($url,$post,'DELETE',$heard=1);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function curlPublic($url,$post,$method = 'GET'){
|
||||
$result = $this->crulGetData($url,$post,$method,$heard=1);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
1100
app/Common/LongbingServiceNotice.php
Executable file
1100
app/Common/LongbingServiceNotice.php
Executable file
File diff suppressed because it is too large
Load Diff
205
app/Common/PublisherApi.php
Executable file
205
app/Common/PublisherApi.php
Executable file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
namespace app\Common;
|
||||
use PhpAmqpLib\Connection\AMQPStreamConnection;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
use PhpAmqpLib\Wire\AMQPTable;
|
||||
use think\facade\Config;
|
||||
/**
|
||||
* 发布消息Api
|
||||
*/
|
||||
|
||||
class PublisherApi {
|
||||
protected $configs;
|
||||
protected $connection;
|
||||
protected $exchangeName;
|
||||
protected $queueName;
|
||||
protected $routingKey;
|
||||
protected $qos_limit = 20;
|
||||
function __construct() {
|
||||
$this->configs = array(
|
||||
'host' => Config::get('rabbit.rabbit_host'),
|
||||
'port' => Config::get('rabbit.rabbit_port'),
|
||||
'login' => Config::get('rabbit.rabbit_login'),
|
||||
'password' => Config::get('rabbit.rabbit_passwd'),
|
||||
'vhost' => Config::get('rabbit.rabbit_vhost')
|
||||
);
|
||||
$this->qos_limit = Config::get('rabbit.rabbit_qos_limit');
|
||||
$this->exchangeName = Config::get('rabbit.rabbit_exchange_name');
|
||||
$this->queueName = Config::get('rabbit.rabbit_query_name');
|
||||
$this->routingKey = Config::get('rabbit.rabbit_key');
|
||||
}
|
||||
public function publishMessage($message) {
|
||||
$this->connection = new AMQPStreamConnection(
|
||||
$this->configs['host'],
|
||||
$this->configs['port'],
|
||||
$this->configs['login'],
|
||||
$this->configs['password'],
|
||||
$this->configs['vhost']
|
||||
);
|
||||
// $channel = new \AMQPChannel($this->conn);
|
||||
// $ex = new \AMQPExchange($channel);
|
||||
// $ex->setName($this->exchangeName);
|
||||
// $ex->setType(AMQP_EX_TYPE_DIRECT);
|
||||
// $ex->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
|
||||
// $ex->declare();
|
||||
// $q = new \AMQPQueue($channel);
|
||||
// $q->setName($this->queueName);
|
||||
// $q->setFlags(AMQP_DURABLE | AMQP_AUTODELETE);
|
||||
// $q->declare();
|
||||
// $q->bind($this->exchangeName, $this->routingKey);
|
||||
// $ex->publish($message, $this->routingKey);
|
||||
// $this->conn->disconnect();
|
||||
$connection = $this->connection;
|
||||
$channel = $connection->channel();
|
||||
$channel->exchange_declare($this->exchangeName, 'direct', false, false, false);
|
||||
$channel->queue_declare($this->queueName, false, true, false, false, false);
|
||||
$channel->queue_bind($this->queueName, $this->exchangeName, $this->routingKey);
|
||||
|
||||
$msg = new AMQPMessage($message, array(
|
||||
'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,
|
||||
));
|
||||
|
||||
$channel->basic_publish($msg, $this->exchangeName, $this->routingKey);
|
||||
|
||||
$channel->close();
|
||||
$connection->close();
|
||||
}
|
||||
public function delayMessage($message, $expiration = 10000) {
|
||||
$this->connection = new AMQPStreamConnection(
|
||||
$this->configs['host'],
|
||||
$this->configs['port'],
|
||||
$this->configs['login'],
|
||||
$this->configs['password'],
|
||||
$this->configs['vhost']
|
||||
);
|
||||
$connection = $this->connection;
|
||||
// var_dump($connection);die;
|
||||
$channel = $connection->channel();
|
||||
|
||||
$cache_exchange_name = 'cache_exchange' . $expiration;
|
||||
|
||||
$cache_queue_name = 'cache_queue' . $expiration;
|
||||
$channel->exchange_declare($this->exchangeName, 'direct', false, false, false);
|
||||
$channel->exchange_declare($cache_exchange_name, 'direct', false, false, false);
|
||||
|
||||
$tale = new AMQPTable();
|
||||
$tale->set('x-dead-letter-exchange', $this->exchangeName);
|
||||
$tale->set('x-dead-letter-routing-key', $this->routingKey);
|
||||
$tale->set('x-message-ttl', $expiration);
|
||||
$channel->queue_declare($cache_queue_name, false, true, false, false, false,$tale);
|
||||
$channel->queue_bind($cache_queue_name, $cache_exchange_name, '');
|
||||
|
||||
$channel->queue_declare($this->queueName, false, true, false, false, false);
|
||||
$channel->queue_bind($this->queueName, $this->exchangeName, $this->routingKey);
|
||||
|
||||
$msg = new AMQPMessage($message, array(
|
||||
'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,
|
||||
));
|
||||
|
||||
$channel->basic_publish($msg, $cache_exchange_name, '');
|
||||
|
||||
$channel->close();
|
||||
$connection->close();
|
||||
}
|
||||
public function scheduleMessage($message, $taskName, $expiration = 10000) {
|
||||
$this->connection = new AMQPStreamConnection(
|
||||
$this->configs['host'],
|
||||
$this->configs['port'],
|
||||
$this->configs['login'],
|
||||
$this->configs['password'],
|
||||
$this->configs['vhost']
|
||||
);
|
||||
$connection = $this->connection;
|
||||
$channel = $connection->channel();
|
||||
|
||||
$schedule_exchange_name = 'schedule_exchange_' . $taskName;
|
||||
$schedule_queue_name = 'schedule_queue_' . $taskName;
|
||||
|
||||
$channel->exchange_declare($this->exchangeName, 'direct', false, false, false);
|
||||
$channel->exchange_declare($schedule_exchange_name, 'direct', false, false, false);
|
||||
|
||||
$tale = new AMQPTable();
|
||||
$tale->set('x-dead-letter-exchange', $this->exchangeName);
|
||||
$tale->set('x-dead-letter-routing-key', $this->routingKey);
|
||||
$tale->set('x-message-ttl', $expiration);
|
||||
|
||||
$channel->queue_declare($schedule_queue_name, false, false, false, false, false,$tale);
|
||||
$channel->queue_bind($schedule_queue_name, $schedule_exchange_name, '');
|
||||
|
||||
$channel->queue_declare($this->queueName, false, true, false, false, false);
|
||||
$channel->queue_bind($this->queueName, $this->exchangeName, $this->routingKey);
|
||||
|
||||
$msg = new AMQPMessage($message, array(
|
||||
'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,
|
||||
));
|
||||
|
||||
$channel->basic_publish($msg, $schedule_exchange_name, '');
|
||||
|
||||
$channel->close();
|
||||
$connection->close();
|
||||
}
|
||||
public function scheduleInfo($taskName, $expiration = 10000) {
|
||||
$this->connection = new AMQPStreamConnection(
|
||||
$this->configs['host'],
|
||||
$this->configs['port'],
|
||||
$this->configs['login'],
|
||||
$this->configs['password'],
|
||||
$this->configs['vhost']
|
||||
);
|
||||
$connection = $this->connection;
|
||||
$channel = $connection->channel();
|
||||
|
||||
$schedule_queue_name = 'schedule_queue_' . $taskName;
|
||||
|
||||
$tale = new AMQPTable();
|
||||
$tale->set('x-dead-letter-exchange', $this->exchangeName);
|
||||
$tale->set('x-dead-letter-routing-key', $this->routingKey);
|
||||
$tale->set('x-message-ttl', $expiration);
|
||||
$result = $channel->queue_declare($schedule_queue_name, false, false, false, false, false,$tale);
|
||||
|
||||
$channel->close();
|
||||
$connection->close();
|
||||
$result = $result ?: [0, 0];
|
||||
return [
|
||||
'ready' => $result[1],
|
||||
'unacked' => $result[2]
|
||||
];
|
||||
}
|
||||
public function consumer() {
|
||||
$this->connection = new AMQPStreamConnection(
|
||||
$this->configs['host'],
|
||||
$this->configs['port'],
|
||||
$this->configs['login'],
|
||||
$this->configs['password'],
|
||||
$this->configs['vhost'],
|
||||
false, // insist
|
||||
'AMQPLAIN', // login_method
|
||||
null, // login_response
|
||||
'en_US', // locale
|
||||
3, // connection_timeout
|
||||
360, // read_write_timeout
|
||||
null, // context
|
||||
false, // keepalive
|
||||
180 // heartbeat
|
||||
);
|
||||
$connection = $this->connection;
|
||||
$channel = $connection->channel();
|
||||
$channel->exchange_declare($this->exchangeName, 'direct', false, false, false);
|
||||
$channel->queue_declare($this->queueName, false, true, false, false, false);
|
||||
$channel->queue_bind($this->queueName, $this->exchangeName, $this->routingKey);
|
||||
$callback = function ($msg) {
|
||||
// message原文位于消息对象body属性中
|
||||
messagesProcess($msg);
|
||||
};
|
||||
|
||||
//流量控制
|
||||
$channel->basic_qos(null, $this->qos_limit, null);
|
||||
$channel->basic_consume($this->queueName, '', false, false, false, false, $callback);
|
||||
while (count($channel->callbacks)) {
|
||||
$channel->wait();
|
||||
}
|
||||
$channel->close();
|
||||
$connection->close();
|
||||
}
|
||||
}
|
||||
|
||||
26
app/Common/Rsa2.php
Executable file
26
app/Common/Rsa2.php
Executable file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace app\Common;
|
||||
class Rsa2
|
||||
{
|
||||
private $private_key;
|
||||
private $public_key;
|
||||
private $config = array(
|
||||
"digest_alg" => "sha512",
|
||||
"private_key_bits" =>2048,
|
||||
"private_key_type" => OPENSSL_KEYTYPE_RSA
|
||||
);
|
||||
|
||||
function __construct(){
|
||||
$res = openssl_pkey_new($this->config);
|
||||
//生成私钥
|
||||
openssl_pkey_export($res, $this->private_key, null, $this->config);
|
||||
//生成公钥
|
||||
$this->public_key = openssl_pkey_get_details($res)['key'];
|
||||
}
|
||||
public function getKeys() {
|
||||
$result = [];
|
||||
if(!empty($this->private_key)) $result['private_key'] =$this->private_key;
|
||||
if(!empty($this->public_key)) $result['public_key'] =$this->public_key;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
98
app/Common/Rsa2Sign.php
Executable file
98
app/Common/Rsa2Sign.php
Executable file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace app\Common;
|
||||
/**
|
||||
* Created by lb.
|
||||
* User: yangqi
|
||||
* Date: 2019/4/3
|
||||
* Time: 17:56
|
||||
*/
|
||||
class Rsa2Sign
|
||||
{
|
||||
private $PRIVATE_KEY ="private_key";
|
||||
private $PUBLIC_KEY ="public_key";
|
||||
function __construct($keys){
|
||||
$this->PRIVATE_KEY = $keys['private_key'];
|
||||
$this->PUBLIC_KEY = $keys['public_key'];
|
||||
}
|
||||
/**
|
||||
* 获取私钥
|
||||
* @return bool|resource
|
||||
*/
|
||||
private function getPrivateKey()
|
||||
{
|
||||
return openssl_pkey_get_private($this->PRIVATE_KEY);
|
||||
}
|
||||
/**
|
||||
* 获取公钥
|
||||
* @return bool|resource
|
||||
*/
|
||||
private function getPublicKey()
|
||||
{
|
||||
return openssl_pkey_get_public($this->PUBLIC_KEY);
|
||||
}
|
||||
/**
|
||||
* 创建签名
|
||||
* @param string $data 数据
|
||||
* @return null|string
|
||||
*/
|
||||
public function createSign($data = '')
|
||||
{
|
||||
// var_dump(self::getPrivateKey());die;
|
||||
if (!is_string($data)) {
|
||||
return null;
|
||||
}
|
||||
return openssl_sign($data, $sign, $this->getPrivateKey(),OPENSSL_ALGO_SHA256 ) ? base64_encode(base64_encode($sign)) : null;
|
||||
}
|
||||
/**
|
||||
* 验证签名
|
||||
* @param string $data 数据
|
||||
* @param string $sign 签名
|
||||
* @return bool
|
||||
*/
|
||||
public function verifySign($data = '', $sign = '')
|
||||
{
|
||||
if (!is_string($sign) || !is_string($sign)) {
|
||||
return false;
|
||||
}
|
||||
$sign = base64_decode($sign);
|
||||
return (bool)openssl_verify(
|
||||
$data,
|
||||
base64_decode($sign),
|
||||
$this->getPublicKey(),
|
||||
OPENSSL_ALGO_SHA256
|
||||
);
|
||||
}
|
||||
/**
|
||||
* 加密
|
||||
* @param string $data 数据
|
||||
* @return string $result
|
||||
*/
|
||||
public function encrypt($data){
|
||||
$key = openssl_pkey_get_public($this->PUBLIC_KEY);
|
||||
if (!$key) {
|
||||
return false;
|
||||
}
|
||||
$return_en = openssl_public_encrypt($data, $crypted, $key);
|
||||
if (!$return_en) {
|
||||
return false;
|
||||
}
|
||||
$eb64_cry = base64_encode($crypted);
|
||||
return $eb64_cry;
|
||||
}
|
||||
/**
|
||||
* 解密
|
||||
* @param string $data 数据
|
||||
* @return string $result
|
||||
*/
|
||||
public function decrypt($data){
|
||||
$private_key = openssl_pkey_get_private($this->PRIVATE_KEY);
|
||||
if (!$private_key) {
|
||||
return false;
|
||||
}
|
||||
$return_check = openssl_private_decrypt(base64_decode($data), $decrypted, $private_key);
|
||||
if (!$return_check) {
|
||||
return false;
|
||||
}
|
||||
return $decrypted;
|
||||
}
|
||||
}
|
||||
68
app/Common/UniPush.php
Executable file
68
app/Common/UniPush.php
Executable file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
namespace app\Common;
|
||||
use think\facade\Config;
|
||||
require_once(APP_PATH .'extend/uniPush/igetui.php');
|
||||
require_once(APP_PATH .'extend/uniPush/igetui/template/notify/IGt.Notify.php');
|
||||
|
||||
|
||||
class UniPush()
|
||||
{
|
||||
privated $cid;
|
||||
privated $title = '';
|
||||
privated $content = '';
|
||||
privated $payload = '';
|
||||
privated $package = '';//包名
|
||||
function __construct(){
|
||||
|
||||
}
|
||||
|
||||
// 返回错误信息
|
||||
function error($des){
|
||||
echo '!!ERROR!!'.PHP_EOL;
|
||||
echo $des;
|
||||
echo PHP_EOL;
|
||||
}
|
||||
|
||||
// 创建支持厂商通道的透传消息
|
||||
function createPushMessage($p, $i, $t, $c){
|
||||
$template = new IGtTransmissionTemplate();
|
||||
$template->set_appId(APPID);//应用appid
|
||||
$template->set_appkey(APPKEY);//应用appkey
|
||||
$template->set_transmissionType(2);//透传消息类型:1为激活客户端启动
|
||||
|
||||
//为了保证应用切换到后台时接收到个推在线推送消息,转换为{title:'',content:'',payload:''}格式数据,UniPush将在系统通知栏显示
|
||||
//如果开发者不希望由UniPush处理,则不需要转换为上述格式数据(将触发receive事件,由应用业务逻辑处理)
|
||||
//注意:iOS在线时转换为此格式也触发receive事件
|
||||
$payload = array('title'=>$t, 'content'=>$c);
|
||||
$pj = json_decode($p, TRUE);
|
||||
$payload['payload'] = is_array($pj)?$pj:$p;
|
||||
$template->set_transmissionContent(json_encode($payload));//透传内容
|
||||
|
||||
//兼容使用厂商通道传输
|
||||
$notify = new IGtNotify();
|
||||
$notify->set_title($t);
|
||||
$notify->set_content($c);
|
||||
$notify->set_intent($i);
|
||||
$notify->set_type(NotifyInfo_type::_intent);
|
||||
$template->set3rdNotifyInfo($notify);
|
||||
|
||||
|
||||
//iOS平台设置APN信息,如果应用离线(不在前台运行)则通过APNS下发推送消息
|
||||
$apn = new IGtAPNPayload();
|
||||
$apn->alertMsg = new DictionaryAlertMsg();
|
||||
$apn->alertMsg->body = $c;
|
||||
$apn->add_customMsg('payload', is_array($pj)?json_encode($pj):$p);//payload兼容json格式字符串
|
||||
$template->set_apnInfo($apn);
|
||||
//个推老版本接口: $template ->set_pushInfo($actionLocKey,$badge,$message,$sound,$payload,$locKey,$locArgs,$launchImage);
|
||||
//$template->set_pushInfo('', 0, $c, '', $p, '', '', '');
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
public function push()
|
||||
{
|
||||
// 生成指定格式的intent支持厂商推送通道
|
||||
$intent = "intent:#Intent;action=android.intent.action.oppopush;launchFlags=0x14000000;component={$package}/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title={$title};S.content={$content};S.payload={$payload};end";
|
||||
pushMessageToSingle(createPushMessage($payload,$intent,$title,$content), $cid);
|
||||
}
|
||||
}
|
||||
359
app/Common/Upload.php
Executable file
359
app/Common/Upload.php
Executable file
@@ -0,0 +1,359 @@
|
||||
<?php
|
||||
namespace app\Common;
|
||||
|
||||
use app\common\model\CoreAttachment;
|
||||
use OSS\Core\OssException;
|
||||
use think\helper\Arr;
|
||||
use think\Request;
|
||||
use Qiniu\Auth;
|
||||
use Qiniu\Storage\UploadManager;
|
||||
use think\Image;
|
||||
use Qcloud\Cos\Client;
|
||||
use think\Session;
|
||||
use think\facade\Db;
|
||||
use think\facade\Filesystem;
|
||||
class Upload {
|
||||
|
||||
protected $request;
|
||||
protected $config;//配置
|
||||
protected $uniacid;
|
||||
protected $path_type;//图片 音频 视频
|
||||
protected $attachment_model;
|
||||
protected $is_weiqin = false;
|
||||
/**
|
||||
* 架构函数
|
||||
* @param Request $request Request对象
|
||||
* @access public
|
||||
*/
|
||||
public function __construct($uniacid = '7777')
|
||||
{
|
||||
$this->uniacid = $uniacid;
|
||||
$this->config = longbingGetOssConfig($uniacid);
|
||||
$this->is_weiqin = longbingIsWeiqin();
|
||||
}
|
||||
|
||||
//上传
|
||||
public function upload($type ,$file,$config=array())
|
||||
{
|
||||
|
||||
if(!empty($config)){
|
||||
|
||||
$this->config = $config;
|
||||
|
||||
}
|
||||
$base_path = '/';
|
||||
$type_data = 1;
|
||||
switch($type)
|
||||
{
|
||||
//图片
|
||||
case 'picture':
|
||||
$base_path = $base_path . 'image/';
|
||||
$type_data = 1;
|
||||
break;
|
||||
//音频
|
||||
case 'audio':
|
||||
$base_path = $base_path . 'audio/';
|
||||
$type_data = 2;
|
||||
break;
|
||||
//视频
|
||||
case 'video':
|
||||
$base_path = $base_path . 'video/';
|
||||
$type_data = 3;
|
||||
break;
|
||||
//证书
|
||||
case 'cert':
|
||||
$base_path = $base_path . 'cert/';
|
||||
$type_data = 4;
|
||||
break;
|
||||
//证书
|
||||
case 'wxuploadkey':
|
||||
$base_path = $base_path . 'wxuploadkey/';
|
||||
$type_data = 4;
|
||||
break;
|
||||
default:
|
||||
$base_path = $base_path . 'image/';
|
||||
$type_data = 1;
|
||||
break;
|
||||
}
|
||||
//根据时间生成路径
|
||||
$base_path = $base_path . $this->uniacid . '/' . date('y') . '/' . date('m');
|
||||
|
||||
$info = null;
|
||||
$upload_status = false;
|
||||
|
||||
// dump($this->checkFile($type ,$file));exit;
|
||||
//数据检查
|
||||
if($this->checkFile($type ,$file))
|
||||
{
|
||||
$file_name = null;
|
||||
//本地保存
|
||||
if(in_array($type, ['cert','wxuploadkey'])){
|
||||
$file_name = $this->uniacid . '_' . $file->getOriginalName();
|
||||
$this->config['open_oss'] = 0;
|
||||
}
|
||||
$info_path = $this->fileLoaclSave($base_path ,$file ,$file_name);
|
||||
//获取数据
|
||||
$info = $this->fileInfo($info_path ,$file->getOriginalName() ,$type_data);
|
||||
//云服务器上传
|
||||
if(isset($this->config['open_oss']))
|
||||
{
|
||||
switch($this->config['open_oss'])
|
||||
{
|
||||
//本地
|
||||
case 0:
|
||||
$upload_status = true;
|
||||
$info['longbing_driver'] = 'loacl';
|
||||
break;
|
||||
case 1:
|
||||
$oss_res = $this->aliyunUpload($info_path);
|
||||
|
||||
if(isset($this->config['aliyun_base_dir']) && !empty($this->config['aliyun_base_dir'])) $info_path = $this->config['aliyun_base_dir'] . '/' . $info_path;
|
||||
if(in_array(substr($info_path,0,1) ,['/' ,"/"])) {
|
||||
$info_path = substr($info_path,1,(strlen($info_path)-1));
|
||||
}
|
||||
$info['attachment'] = $info_path;
|
||||
$info['longbing_driver'] = 'aliyun';
|
||||
if(isset($oss_res['info']['url'])) $upload_status = true;
|
||||
break;
|
||||
case 2:
|
||||
$oss_res = $this->qiniuUpload($info_path);
|
||||
$info['longbing_driver'] = 'qiniuyun';
|
||||
if(!empty($oss_res) && empty($oss_res[1])) $upload_status = true;
|
||||
break;
|
||||
case 3:
|
||||
$oss_res = $this->tenxunUpoload($info_path);
|
||||
|
||||
$info['longbing_driver'] = 'tengxunyun';
|
||||
if(isset($oss_res['ETag']) && isset($oss_res['ObjectURL'])) $upload_status = true;
|
||||
break;
|
||||
default:
|
||||
$info['longbing_driver'] = 'loacl';
|
||||
$upload_status = true;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
$upload_status = true;
|
||||
$info['longbing_driver'] = 'loacl';
|
||||
}
|
||||
}
|
||||
if(!$upload_status) $info = null;
|
||||
|
||||
// dump($info);exit;
|
||||
return $info;
|
||||
}
|
||||
|
||||
//检查上传
|
||||
public function uploadFile($info_path){
|
||||
$info = [];
|
||||
$upload_status = false;
|
||||
if(isset($this->config['open_oss']))
|
||||
{
|
||||
switch($this->config['open_oss'])
|
||||
{
|
||||
//本地
|
||||
case 0:
|
||||
$upload_status = true;
|
||||
$info['longbing_driver'] = 'loacl';
|
||||
break;
|
||||
case 1:
|
||||
$oss_res = $this->aliyunUpload($info_path);
|
||||
if(isset($this->config['aliyun_base_dir']) && !empty($this->config['aliyun_base_dir'])) $info_path = $this->config['aliyun_base_dir'] . '/' . $info_path;
|
||||
if(in_array(substr($info_path,0,1) ,['/' ,"/"])) {
|
||||
$info_path = substr($info_path,1,(strlen($info_path)-1));
|
||||
}
|
||||
$info['attachment'] = $info_path;
|
||||
$info['longbing_driver'] = 'aliyun';
|
||||
if(isset($oss_res['info']['url'])) $upload_status = true;
|
||||
break;
|
||||
case 2:
|
||||
$oss_res = $this->qiniuUpload($info_path);
|
||||
$info['longbing_driver'] = 'qiniuyun';
|
||||
if(empty($oss_res[1])) $upload_status = true;
|
||||
break;
|
||||
case 3:
|
||||
$oss_res = $this->tenxunUpoload($info_path);
|
||||
$info['longbing_driver'] = 'tengxunyun';
|
||||
if(isset($oss_res['ETag']) && isset($oss_res['ObjectURL'])) $upload_status = true;
|
||||
break;
|
||||
default:
|
||||
$info['longbing_driver'] = 'loacl';
|
||||
$upload_status = true;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
$upload_status = true;
|
||||
$info['longbing_driver'] = 'loacl';
|
||||
}
|
||||
return $upload_status;
|
||||
}
|
||||
//检查
|
||||
public function checkFile($type ,$file)
|
||||
{
|
||||
$result = false;
|
||||
switch($type)
|
||||
{
|
||||
case 'picture':
|
||||
$result = validate(['image'=>'filesize:2097152|fileExt:jpg,jpeg,bmp,png|image:*'])->check([$file]);
|
||||
break;
|
||||
case 'audio':
|
||||
$result = validate(['audio'=>'filesize:2097152|fileExt:mp3,wma,wav,m4a'])->check([$file]);
|
||||
break;
|
||||
case 'video':
|
||||
$result = validate(['video'=>'filesize:2097152|fileExt:wmv,mp4,avi,mpg,rmvb'])->check([$file]);
|
||||
break;
|
||||
case 'cert':
|
||||
$result = validate(['cert'=>'filesize:2097152|fileExt:cert'])->check([$file]);
|
||||
break;
|
||||
case 'wxuploadkey':
|
||||
$result = validate(['cert'=>'filesize:2097152|fileExt:cert'])->check([$file]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
//生成返回数据
|
||||
public function fileInfo($path ,$file_name ,$type_data)
|
||||
{
|
||||
$result = array(
|
||||
'attachment' => ltrim($path,'/'),
|
||||
'uniacid' => $this->config['uniacid'],
|
||||
'filename' => $file_name,
|
||||
'createtime' => time(),
|
||||
'type' => $type_data
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//本地保存
|
||||
public function fileLoaclSave($path ,$file ,$file_name = null)
|
||||
{
|
||||
if(empty($file_name)) $file_name = uuid() . '.' . $file->getOriginalExtension();
|
||||
|
||||
// dump($path ,$file ,$file_name);exit;
|
||||
//保存
|
||||
$info = Filesystem::disk('longbing')->putFileAs($path ,$file ,$file_name);
|
||||
return $info;
|
||||
}
|
||||
|
||||
//阿里云上传
|
||||
public function aliyunUpload($path)
|
||||
{
|
||||
//左边的/去掉
|
||||
$path = ltrim($path,'/');
|
||||
try{
|
||||
$bucket = $this->config['aliyun_bucket'];
|
||||
$filePath = FILE_UPLOAD_PATH . $path;
|
||||
if(isset($this->config['aliyun_base_dir']) && !empty($this->config['aliyun_base_dir'])) $path = $this->config['aliyun_base_dir'] . '/' . $path;
|
||||
if(in_array(substr($path,0,1) ,['/' ,"/"])) {
|
||||
$path = substr($path,1,(strlen($path)-1));
|
||||
}
|
||||
if (file_exists($filePath)) {
|
||||
//实例化OSS
|
||||
require_once dirname(__FILE__) . '/extend/aliyuncs/oss-sdk-php/autoload.php';
|
||||
$ossClient =new \OSS\OssClient($this->config['aliyun_access_key_id']
|
||||
,$this->config['aliyun_access_key_secret']
|
||||
,$this->config['aliyun_endpoint']);
|
||||
//uploadFile的上传方法
|
||||
$res=$ossClient->uploadFile($bucket, $path, $filePath);
|
||||
if(is_file($filePath)){
|
||||
unlink($filePath);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}catch(OssException $e) {
|
||||
//如果出错这里返回报错信息
|
||||
return false;
|
||||
//return $e->getMessage();
|
||||
}
|
||||
//否则,完成上传操作
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
//七牛云上传
|
||||
public function qiniuUpload($path)
|
||||
{
|
||||
try{
|
||||
//加载驱动
|
||||
require_once dirname(__FILE__) . '/extend/qiniu/autoload.php';
|
||||
//左边的/去掉
|
||||
$path = ltrim($path,'/');
|
||||
// 需要填写你的 Access Key 和 Secret Key
|
||||
$accessKey = $this->config['qiniu_accesskey'];
|
||||
$secretKey = $this->config['qiniu_secretkey'];
|
||||
$bucket = $this->config['qiniu_bucket'];
|
||||
// 构建鉴权对象
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
// 生成上传 Token
|
||||
$token = $auth->uploadToken($bucket);
|
||||
//获取本地文件
|
||||
$filePath = FILE_UPLOAD_PATH . $path;
|
||||
//上传
|
||||
$client = new UploadManager();
|
||||
list($ret, $err) = $client->putFile($token, $path, $filePath);
|
||||
if(is_file($filePath)){
|
||||
unlink($filePath);
|
||||
}
|
||||
return array($ret,$err);
|
||||
}catch (\Exception $e){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//腾讯云上传
|
||||
public function tenxunUpoload($path)
|
||||
{
|
||||
try{
|
||||
$path = ltrim($path,'/');//左边的/去掉
|
||||
//加载驱动
|
||||
require dirname(__FILE__) . '/extend/tencentcloud/vendor/autoload.php';
|
||||
|
||||
// dump(dirname(__FILE__) . '/extend/tencentcloud/vendor/autoload.php');exit;
|
||||
// 需要填写你的 Access Key 和 Secret Key
|
||||
$appid = $this->config['tenxunyun_appid'];
|
||||
$secretid = $this->config['tenxunyun_secretid'];
|
||||
$secretkey= $this->config['tenxunyun_secretkey'];
|
||||
$bucket = $this->config['tenxunyun_bucket'];
|
||||
$region = $this->config['tenxunyun_region'];
|
||||
$yuming = $this->config['tenxunyun_yuming'];
|
||||
|
||||
//初始化对象
|
||||
$cosClient = new Client(array(
|
||||
'region' => $region, #地域,如ap-guangzhou,ap-beijing-1
|
||||
'credentials' => array(
|
||||
'secretId' => $secretid,
|
||||
'secretKey'=> $secretkey,
|
||||
),
|
||||
));
|
||||
|
||||
// 若初始化 Client 时未填写 appId,则 bucket 的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式
|
||||
// $bucket = $bucket . '-' . $appid;
|
||||
// 要上传文件的本地路径
|
||||
$body = FILE_UPLOAD_PATH . $path;
|
||||
|
||||
|
||||
try {
|
||||
$result = $cosClient->putObject(array(
|
||||
'Bucket' => $bucket,
|
||||
'Key' => $path,
|
||||
'Body' => file_get_contents($body)
|
||||
));
|
||||
|
||||
if(is_file($body)){
|
||||
unlink($body);
|
||||
}
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}catch(\Exception $e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
75
app/Common/WeChatCode.php
Executable file
75
app/Common/WeChatCode.php
Executable file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
namespace app\Common;
|
||||
|
||||
use think\Request;
|
||||
use think\Image;
|
||||
use think\Session;
|
||||
use think\facade\Db;
|
||||
use app\Common\Upload;
|
||||
//生成微信小程序码
|
||||
class WeChatCode {
|
||||
//小程序唯一识别码
|
||||
protected $uniacid;
|
||||
//系统配置
|
||||
protected $config;
|
||||
//accesstoken
|
||||
protected $access_token;
|
||||
//构造函数
|
||||
public function __construct($uniacid)
|
||||
{
|
||||
$this->uniacid = $uniacid;
|
||||
$this->config = longbingGetAppConfig($uniacid);
|
||||
$this->access_token = $this->getAccessToken();
|
||||
}
|
||||
|
||||
//获取accesstoken
|
||||
public function getAccessToken()
|
||||
{
|
||||
return longbingGetAccessToken($this->uniacid ,true);
|
||||
}
|
||||
|
||||
//获取code (方法一)
|
||||
public function getQRCode($path ,$width = 430)
|
||||
{
|
||||
//url
|
||||
$url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token={$this->access_token}";
|
||||
$post_data = ['path' => $path ,'width' => $width];
|
||||
//发送数据
|
||||
$result = longbingCurl($url ,json_encode($post_data ,true) ,'POTH');
|
||||
return $result;
|
||||
}
|
||||
//获取code (方法二)
|
||||
public function getWxCode($path ,$width = 430 ,$auto_color = true ,$line_color = null ,$is_hyaline = false)
|
||||
{
|
||||
//url
|
||||
$url = "https://api.weixin.qq.com/wxa/getwxacode?access_token={$this->access_token}";
|
||||
$post_data = ['path' => $path ,
|
||||
'width' => $width ,
|
||||
'auto_color' => $auto_color ,
|
||||
'line_color' => $line_color ,
|
||||
'is_hyaline' => $is_hyaline];
|
||||
//生成
|
||||
$result = longbingCurl($url ,json_encode($post_data ,true) ,'POTH');
|
||||
return $result;
|
||||
}
|
||||
//获取code (方法三)
|
||||
public function getUnlimitedCode($scene ,$path = '',$width = 430 ,$auto_color = false ,$line_color = '{"r":0,"g":0,"b":0}' ,$is_hyaline = true)
|
||||
{
|
||||
$access_token = $this->access_token;
|
||||
|
||||
|
||||
// $access_token = '123';
|
||||
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={$access_token}";
|
||||
$post_data = ['scene' => $scene ];
|
||||
if(!empty($width)) $post_data['width'] = $width;
|
||||
if(!empty($auto_color)) $post_data['auto_color'] = $auto_color;
|
||||
// if(!empty($line_color)) $post_data['line_color'] = $line_color;
|
||||
if(!empty($is_hyaline)) $post_data['is_hyaline'] = $is_hyaline;
|
||||
// if(!empty($auto_color)) unset($post_data['line_color']);
|
||||
if(!empty($path)) $post_data['page'] = $path;
|
||||
//生成
|
||||
$result = longbingCurl($url ,json_encode($post_data ,true) ,'POST');
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
52
app/Common/addUserInfo.inc.php
Executable file
52
app/Common/addUserInfo.inc.php
Executable file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
defined( 'LONGBING_NEW_AUTH' ) or define( 'LONGBING_NEW_AUTH', 1 );
|
||||
|
||||
|
||||
$default_card = 0;
|
||||
$default_goods = 0;
|
||||
$default_timeline = 0;
|
||||
$default_message = 0;
|
||||
$default_custom_qr = 0;
|
||||
$default_copyright = 1;
|
||||
$default_mini = 0;
|
||||
$default_form = 0;
|
||||
$default_plug_auth = 0;
|
||||
$default_article = 0;
|
||||
$default_activity = 0;
|
||||
|
||||
// 版本
|
||||
$version = 0;
|
||||
// 无限开
|
||||
$agent = 1;
|
||||
|
||||
$version = intval( $version );
|
||||
|
||||
if ( !is_numeric( $version ) ) {
|
||||
$version = 0;
|
||||
}
|
||||
|
||||
if ( $version == 0 ) {
|
||||
$default_card = 5;
|
||||
$default_goods = 5;
|
||||
$default_timeline = 5;
|
||||
$default_message = 5;
|
||||
$default_custom_qr = 5;
|
||||
$default_copyright = 1;
|
||||
$default_mini = 2;
|
||||
$default_form = 0;
|
||||
$default_plug_auth = 0;
|
||||
} else {
|
||||
$default_mini = $version;
|
||||
}
|
||||
|
||||
if ( $agent == 1 ) {
|
||||
$default_card = 0;
|
||||
$default_goods = 0;
|
||||
$default_timeline = 0;
|
||||
$default_message = 0;
|
||||
$default_custom_qr = 0;
|
||||
$default_copyright = 1;
|
||||
$default_mini = 0;
|
||||
$default_form = 0;
|
||||
$default_plug_auth = 0;
|
||||
}
|
||||
24
app/Common/errorCode.php
Executable file
24
app/Common/errorCode.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace app\Common;
|
||||
/**
|
||||
* error code 说明.
|
||||
* <ul>
|
||||
|
||||
* <li>-41001: encodingAesKey 非法</li>
|
||||
* <li>-41003: aes 解密失败</li>
|
||||
* <li>-41004: 解密后得到的buffer非法</li>
|
||||
* <li>-41005: base64加密失败</li>
|
||||
* <li>-41016: base64解密失败</li>
|
||||
* </ul>
|
||||
*/
|
||||
|
||||
class ErrorCode
|
||||
{
|
||||
public static $OK = 0;
|
||||
public static $IllegalAesKey = -41001;
|
||||
public static $IllegalIv = -41002;
|
||||
public static $IllegalBuffer = -41003;
|
||||
public static $DecodeBase64Error = -41004;
|
||||
}
|
||||
|
||||
?>
|
||||
620
app/Common/extend/LongbingUpgrade.php
Executable file
620
app/Common/extend/LongbingUpgrade.php
Executable file
@@ -0,0 +1,620 @@
|
||||
<?php
|
||||
class LongbingUpgrade{
|
||||
|
||||
private $uniacid ;
|
||||
//产品/商品名称
|
||||
private $goods_name ;
|
||||
|
||||
|
||||
//授权服务器地址
|
||||
private $base_url ;
|
||||
//检查授权的地址
|
||||
private $check_url ;
|
||||
//上传小程序
|
||||
private $uploadWxapp_url ;
|
||||
private $get_auth_url ;
|
||||
|
||||
//获取授权详情
|
||||
private $get_domain_param_url;
|
||||
|
||||
private $http_host ;
|
||||
private $server_name ;
|
||||
private $request_time ;
|
||||
|
||||
|
||||
private $public_key ;
|
||||
private $domain_name_info ;
|
||||
|
||||
|
||||
private $goods_version_info ; //版本的基本信息
|
||||
private $goods_version_updata_info ; //包括文件下载地址 和 解压密码
|
||||
|
||||
|
||||
private $errorMsg = '授权失败,请联系系统提供商,Tel:15680635005 。';
|
||||
|
||||
private $is_debug = false ;
|
||||
private $token_path;
|
||||
|
||||
function __construct($uniacid , $goodsName ,$is_debug = false ){
|
||||
|
||||
//是否开启调试
|
||||
$this->is_debug = $is_debug ;
|
||||
|
||||
$this->token_path = dirname(__FILE__).'/token.key';
|
||||
|
||||
$this->uniacid = $uniacid .'';
|
||||
|
||||
$this->goods_name = $goodsName;
|
||||
$this->base_url = 'http://shouquan.migugu.com/';
|
||||
$this->base_url = $this->is_debug ? 'http://shouquan.migugu.com/' : 'http://auth.soqq.com.cn/' ;
|
||||
$this->base_url = 'http://auth.soqq.com.cn/'; //ToDo 调试模式 线下接口 授权接口写死
|
||||
|
||||
$this->check_url = $this->base_url .'auth/home.Index/index';
|
||||
$this->uploadWxapp_url = $this->base_url .'auth/home.Index/uploadWxapp';
|
||||
$this->get_auth_url = $this->base_url .'auth/home.Index/getAuth' ;
|
||||
$this->get_domain_param_url = $this->base_url .'auth/home.Index/domain_param' ;
|
||||
$this->get_wxapp_version_url = $this->base_url .'auth/home.Index/getWxappVersion' ;
|
||||
$this->clear_up_token = $this->base_url .'auth/home.Index/clearToken' ;
|
||||
|
||||
|
||||
$this->http_host = $_SERVER['HTTP_HOST'];
|
||||
$this->server_name = $_SERVER['SERVER_NAME'];
|
||||
$this->request_time = $_SERVER['REQUEST_TIME'].'';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-08 13:12
|
||||
* @功能说明:
|
||||
*/
|
||||
public function checkAuth(){
|
||||
try {
|
||||
//清除双方授权token --重新获取
|
||||
$this->clearUp();
|
||||
|
||||
$this->public_key = $this->getPublicKey();
|
||||
$this->getUpgradeMsg();
|
||||
|
||||
if(empty($this->public_key)){
|
||||
return $this->returnErrorDataInfo( '(001)'.$this->errorMsg );
|
||||
}else{
|
||||
|
||||
$data['domain'] = $this->domain_name_info ;
|
||||
$data['version'] = $this->goods_version_info ;
|
||||
|
||||
return $this->returnDataInfo($data);
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
return $this->returnErrorDataInfo( "请用授权域名登陆 进行站点绑定" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-08 11:52
|
||||
* @功能说明: 站点授权信息
|
||||
*/
|
||||
private function getAuthMsg(){
|
||||
if(empty($this->domain_name_info) || count($this->domain_name_info) == 0 ){
|
||||
return $this->returnDataInfo([],'(002)'.$this->errorMsg);
|
||||
}else{
|
||||
return $this->returnDataInfo($this->domain_name_info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-05 12:55
|
||||
* @功能说明:
|
||||
*/
|
||||
private function getUpgradeMsg(){
|
||||
|
||||
try{
|
||||
|
||||
$this->public_key = $this->getPublicKey();
|
||||
if(!$this->public_key){
|
||||
return $this->returnErrorDataInfo( "请用授权域名登陆 进行站点绑定" );
|
||||
}
|
||||
|
||||
$siginStr = $this->getSiginData([]);
|
||||
$result = $this->curl_post($this->check_url ,$this->getPostData($siginStr)) ;
|
||||
$result = json_decode( $result,true);
|
||||
|
||||
$data = $result['data'];
|
||||
|
||||
openssl_public_decrypt(base64_decode($data['goods_version_updata_info']), $sigin, $this->public_key);
|
||||
|
||||
$sigin = json_decode($sigin , true) ;
|
||||
|
||||
$this->goods_version_info = $data['goods_version_info'];
|
||||
$this->goods_version_updata_info = $sigin;
|
||||
|
||||
return $this->returnDataInfo($this->goods_version_info);
|
||||
|
||||
}catch (Exception $e){
|
||||
return $this->returnErrorDataInfo( "获取更新信息异常" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-05 14:09
|
||||
* @功能说明: 开始升级
|
||||
*/
|
||||
public function update($toFilePath = null , $tempPaht = null){
|
||||
//获取升级包信息
|
||||
//检查权限
|
||||
//下载升级包
|
||||
//解压升级包
|
||||
//写入版本文件
|
||||
|
||||
if(!$this->goods_version_info && !$this->goods_version_updata_info){
|
||||
$this->getUpgradeMsg();
|
||||
}
|
||||
|
||||
//状态码判断 2020/6/18 16:45 / lichuanming
|
||||
if($this->goods_version_updata_info['url'] === 'ae40000001'){
|
||||
return $this->returnErrorDataInfo ('升级服务已到期') ;
|
||||
}
|
||||
|
||||
$result = $this->get_file($this->goods_version_updata_info['url'] , $tempPaht);
|
||||
|
||||
if($result === false){
|
||||
return $this->returnErrorDataInfo ('下载文件失败') ;
|
||||
}
|
||||
|
||||
$toFilePath = empty($toFilePath) ? './' : $toFilePath ;
|
||||
$this->unzip($result , $toFilePath , $this->goods_version_updata_info['password'] );
|
||||
|
||||
return $this->returnDataInfo([],'更新成功' , '200') ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param string $msg
|
||||
* @param int $code
|
||||
* @功能说明: 返回 json 数据
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-06 21:25
|
||||
*/
|
||||
public function returnDataInfo($data = [] , $msg = '' , $code = 20000){
|
||||
$resultData = [
|
||||
'code' => $code ,
|
||||
'msg' => $msg,
|
||||
'data' => $data
|
||||
];
|
||||
return $resultData ;
|
||||
}
|
||||
|
||||
public function returnErrorDataInfo($msg = '' , $code = -1 , $data = []){
|
||||
return $this->returnDataInfo($data ,$msg ,$code);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-05 16:02
|
||||
* @功能说明:上传微信小程序
|
||||
*/
|
||||
public function uploadWxapp($uploadInfo,$wxapp_version = '')
|
||||
{
|
||||
|
||||
//获取当前系统版本信息
|
||||
//提交需要上传的版本信息
|
||||
//验证系统的平台ID 版本ID 域名 平台ID 模块ID 上传KEY
|
||||
//加密签名
|
||||
//提交上传
|
||||
|
||||
/*try{
|
||||
if(!$this->goods_version_updata_info){
|
||||
$this->getUpgradeMsg();
|
||||
}
|
||||
|
||||
$siginStr = $this->getSiginData();
|
||||
|
||||
$postData = $this->getPostData($siginStr);
|
||||
$uploadInfo = $this->getSiginDataByOpenSSL($uploadInfo);
|
||||
$this->log("uploadWxapp = uploadInfo", $uploadInfo);
|
||||
$postData['ext_data'] = $uploadInfo;
|
||||
|
||||
$this->log("uploadWxapp = postData", $postData);
|
||||
|
||||
$result = $this->curl_post( $this->uploadWxapp_url ,$postData) ;
|
||||
|
||||
$this->log( "获取授权信息一" ,$result);
|
||||
|
||||
$result = json_decode( $result,true);
|
||||
|
||||
$this->log( "获取授权信息二" ,$result);
|
||||
|
||||
return $this->returnDataInfo($result);
|
||||
}catch (\Exception $e){
|
||||
return $this->returnErrorDataInfo('上传失败');
|
||||
}*/
|
||||
|
||||
|
||||
try{
|
||||
$postData = $this->getPostData('');
|
||||
$postData['ext_data'] = json_encode($uploadInfo);
|
||||
$postData['wxapp_version'] = $wxapp_version; //新增微信版本号
|
||||
|
||||
$this->log("uploadWxapp = postData", $postData);
|
||||
|
||||
$result = $this->curl_post( $this->uploadWxapp_url ,$postData) ;
|
||||
|
||||
$this->log( "获取授权信息一" ,$result);
|
||||
|
||||
$result = json_decode( $result,true);
|
||||
|
||||
$this->log( "获取授权信息二" ,$result);
|
||||
|
||||
return empty($result) ? $this->returnErrorDataInfo('上传繁忙,稍后再试。。(001)') : $result;
|
||||
}catch (\Exception $e){
|
||||
return $this->returnErrorDataInfo('上传繁忙,稍后再试。。(002)');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
**@param $version_no
|
||||
* @功能说明: 当前系统版本号
|
||||
* @author lichuanming
|
||||
* @DataTime: 2020/6/22 17:31
|
||||
*/
|
||||
public function getWxappVersion($version_no){
|
||||
try{
|
||||
$postData = $this->getPostData('');
|
||||
|
||||
$postData['version'] = $version_no;
|
||||
$this->log("uploadWxapp = postData", $postData);
|
||||
|
||||
$result = $this->curl_post( $this->get_wxapp_version_url ,$postData) ;
|
||||
$this->log( "获取版本信息一" ,$result);
|
||||
|
||||
$result = json_decode( $result,true);
|
||||
|
||||
$this->log( "获取版本信息二" ,$result);
|
||||
|
||||
return $result['data'];
|
||||
}catch (\Exception $e){
|
||||
return $this->returnErrorDataInfo('无法获取小程序版本信息');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
**@author lichuanming
|
||||
* @DataTime: 2020/6/18 19:13
|
||||
* @功能说明: 获取saas端的值
|
||||
*/
|
||||
public function getsAuthConfig(){
|
||||
|
||||
$this->public_key = $this->getPublicKey();
|
||||
|
||||
if(empty($this->public_key )){
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
$siginStr = $this->getSiginData([]);
|
||||
|
||||
$result = $this->curl_post($this->get_domain_param_url ,$this->getPostData($siginStr)) ;
|
||||
|
||||
$result = json_decode( $result,true);
|
||||
|
||||
$param_list = $result['data']['param_list'];
|
||||
|
||||
if(is_array($param_list)){
|
||||
foreach ($param_list as $key =>$item){
|
||||
$param = '';
|
||||
openssl_public_decrypt(base64_decode($item), $param, $this->public_key);
|
||||
$param_list[$key] = $param;
|
||||
}
|
||||
}
|
||||
|
||||
return $param_list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $siginStr
|
||||
* @功能说明: 获取提交信息
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-05 16:35
|
||||
*/
|
||||
private function getPostData($siginStr)
|
||||
{
|
||||
|
||||
$postData = $this->getPublicPostData();
|
||||
$postData['sigin' ] = $siginStr;
|
||||
|
||||
return $postData ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-05 16:13
|
||||
* @功能说明: 获取签名信息
|
||||
*/
|
||||
private function getSiginData($extData = [] , $siginType = 1 )
|
||||
{
|
||||
|
||||
$data = $this->getPublicPostData();
|
||||
if (!empty($extData)){
|
||||
$data['ext_data'] = $extData ;
|
||||
}
|
||||
|
||||
ksort($data);
|
||||
$str_data = json_encode($data);
|
||||
|
||||
//$siginType = 1 采用 公钥加密
|
||||
|
||||
if($siginType == 1 ){
|
||||
openssl_public_encrypt($str_data, $encrypted, $this->public_key);
|
||||
|
||||
if(empty($encrypted)){
|
||||
return false ;
|
||||
}
|
||||
//处理特殊字符
|
||||
$encrypted = base64_encode($encrypted);
|
||||
|
||||
}else{ #其他只做数据签名,不做信息加密
|
||||
$encrypted =$this->getSiginDataByHash($data);
|
||||
}
|
||||
return $encrypted ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function getSiginDataByOpenSSL($data){
|
||||
$str_data = is_array($data) ? json_encode($data) : $data;
|
||||
openssl_public_encrypt($str_data, $encrypted, $this->public_key);
|
||||
if(empty($encrypted)){
|
||||
return false ;
|
||||
}
|
||||
//处理特殊字符
|
||||
$encrypted = base64_encode($encrypted);
|
||||
return $encrypted;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @功能说明: 普通数据签名算法(只支持 str 和数组 签名 )
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-06 15:10
|
||||
*/
|
||||
private function getSiginDataByHash($data){
|
||||
$data['token'] = $data['token']?$data['token']:'';
|
||||
$this->log( 'getSiginDataByHash data ' , $data);
|
||||
$data = is_array( $data ) ? json_encode($data) : (is_string($data) ? $data : time() . '') . 'LongbingShuixian';
|
||||
|
||||
$siginStr = hash( 'sha256', $data) ;
|
||||
|
||||
return $siginStr ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-06 14:45
|
||||
* @功能说明: 获取公共提交数据
|
||||
*/
|
||||
private function getPublicPostData(){
|
||||
$app_model_name = config('app.AdminModelList')['app_model_name'];
|
||||
$token = @file_get_contents($this->token_path) ;
|
||||
$token = $token?json_decode($token,true):'';
|
||||
if(!empty($token)){
|
||||
$token = $token['token'];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'uniacid' => $this->uniacid ,
|
||||
'app_model_name' => $app_model_name , //2020/6/22 新增参数 By.lichuanming
|
||||
'goods_name' => $this->goods_name,
|
||||
'http_host' => $this->http_host ,
|
||||
'server_name' => $this->server_name ,
|
||||
'request_time' => $this->request_time ,
|
||||
'token' => $token
|
||||
];
|
||||
return $data ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param string $folder
|
||||
* @功能说明: 下载文件
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-05 14:15
|
||||
*/
|
||||
private function get_file($url, $folder = './data/upgradex/') {
|
||||
set_time_limit(24 * 60 * 60);
|
||||
$target_dir = $folder . '';
|
||||
if (!is_dir($target_dir)) {
|
||||
mkdir($target_dir, 0777, true);
|
||||
}
|
||||
$newfname = date('Ymd') . rand(1000, 10000000) . uniqid() . '.zip';
|
||||
$newfname = $target_dir . $newfname;
|
||||
$file = @fopen($url, "rb");
|
||||
if ($file) {
|
||||
$newf = fopen($newfname, "wb");
|
||||
if ($newf) while (!feof($file)) {
|
||||
fwrite($newf, fread($file, 1024 * 8) , 1024 * 8);
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
if ($newf) {
|
||||
fclose($newf);
|
||||
}
|
||||
|
||||
}else{
|
||||
return false ;
|
||||
}
|
||||
|
||||
return $newfname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
* @param $toFilepath
|
||||
* @param null $password 解压密码
|
||||
* @功能说明: 解压文件
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-05 14:44
|
||||
*/
|
||||
private function unzip($filename , $toFilepath , $password = null){
|
||||
$zip = new ZipArchive;
|
||||
$res = $zip->open($filename);
|
||||
if ($res === true){
|
||||
$password && $zip->setPassword($password); //解压密码
|
||||
$zip->extractTo($toFilepath);
|
||||
$zip->close();
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param $value
|
||||
* @功能说明: 打印日志
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-05 13:29
|
||||
*/
|
||||
public function log($key , $value){
|
||||
//关闭和开启调试
|
||||
if($this->is_debug)
|
||||
{
|
||||
echo $key ." = " .(is_array($value) ? json_encode($value) : $value) . '<br /><br /><br /> ';
|
||||
}else{
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-05 13:34
|
||||
* @功能说明: 获取秘钥
|
||||
*/
|
||||
private function getPublicKey(){
|
||||
|
||||
|
||||
if(!empty($this->public_key)){
|
||||
$this->log( "已经获得 " , $this->public_key);
|
||||
return $this->public_key ;
|
||||
}
|
||||
|
||||
$this->log('获取秘钥:' ,'开始');
|
||||
$siginStr = $this->getSiginData([] , 2);
|
||||
$this->log('获取秘钥 sigin:' ,$siginStr);
|
||||
|
||||
$result = $this->curl_post($this->get_auth_url ,$this->getPostData($siginStr) ) ;
|
||||
$this->log('获取秘钥 result:' ,$result);
|
||||
|
||||
$result = json_decode( $result,true);
|
||||
// todo 需要判断返回结果是否正确
|
||||
|
||||
$this->domain_name_info = $result['data']['domain_name_info'];
|
||||
|
||||
//写入token文件
|
||||
$this->log("获取秘钥 保持token路径: " , dirname(__FILE__));
|
||||
|
||||
$token = $result['data']['token'];
|
||||
$resultWriteToken = $this->writein_token($token);
|
||||
$this->log("获取秘钥 写入token: " , $resultWriteToken ? '成功' : '失败' );
|
||||
|
||||
$this->public_key = $result['data']['public_key'];
|
||||
return $this->public_key;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param array $data
|
||||
* @功能说明: post 请求
|
||||
* @author jingshuixian
|
||||
* @DataTime: 2020-06-05 12:53
|
||||
*/
|
||||
private function curl_post($url , $data=array()){
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
|
||||
// POST数据
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
// 把post的变量加上
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
|
||||
$output = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
**@param array $token
|
||||
* @功能说明: token写入
|
||||
* @author lichuanming
|
||||
* @DataTime: 2020/6/19 11:35
|
||||
*/
|
||||
private function writein_token($token):bool {
|
||||
$resultWriteToken = false;
|
||||
if(is_array($token)){
|
||||
//数据正常 直接保存
|
||||
$resultWriteToken = file_put_contents($this->token_path , json_encode($token));
|
||||
|
||||
}else{
|
||||
//读取原有token 数据
|
||||
$token = @file_get_contents($this->token_path) ;
|
||||
$token = $token?json_decode($token,true):'';
|
||||
|
||||
if(!empty($token)){
|
||||
if($token['token_expiration_time'] < time()){
|
||||
$token['token'] = '';
|
||||
//写入空token
|
||||
$resultWriteToken = file_put_contents($this->token_path , json_encode($token));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $resultWriteToken?true:false;
|
||||
}
|
||||
|
||||
/**
|
||||
**@author lichuanming
|
||||
* @DataTime: 2020/6/23 14:33
|
||||
* @功能说明: 重置双方通讯token
|
||||
*/
|
||||
private function clearUp(){
|
||||
//读取原有token 数据
|
||||
$token = @file_get_contents($this->token_path) ;
|
||||
$token = $token?json_decode($token,true):'';
|
||||
|
||||
if(!empty($token)){
|
||||
if($token['token_expiration_time'] < time() || !$token['token']){ //token 过期
|
||||
$this->public_key = $this->getPublicKey();
|
||||
$siginStr = $this->getSiginData([]);
|
||||
|
||||
$result = $this->curl_post($this->clear_up_token,$this->getPostData($siginStr));
|
||||
$result = json_decode($result,true);
|
||||
if($result['data']['clear']){ //清除成功
|
||||
$this->public_key = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
256
app/Common/extend/alibabacloud/client/CHANGELOG.md
Executable file
256
app/Common/extend/alibabacloud/client/CHANGELOG.md
Executable file
@@ -0,0 +1,256 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 1.5.16 - 2019-08-21
|
||||
- Updated Endpoints Data.
|
||||
|
||||
## 1.5.15 - 2019-08-14
|
||||
- Improved Client.
|
||||
|
||||
|
||||
## 1.5.14 - 2019-07-25
|
||||
- Improved Credential Filter.
|
||||
|
||||
|
||||
## 1.5.13 - 2019-07-18
|
||||
- Improved API Resolver.
|
||||
|
||||
|
||||
## 1.5.12 - 2019-06-20
|
||||
- Fixed Signature for ROA.
|
||||
|
||||
|
||||
## 1.5.11 - 2019-06-14
|
||||
- Added endpoint rules.
|
||||
|
||||
|
||||
## 1.5.10 - 2019-06-13
|
||||
- Improved `Resovler`.
|
||||
- Updated `endpoints`.
|
||||
|
||||
|
||||
## 1.5.9 - 2019-06-04
|
||||
- Improved `UUID`.
|
||||
|
||||
|
||||
## 1.5.8 - 2019-05-30
|
||||
- Improved `Arrays`.
|
||||
|
||||
|
||||
## 1.5.7 - 2019-05-29
|
||||
- Improved `uuid`.
|
||||
|
||||
|
||||
## 1.5.6 - 2019-05-29
|
||||
- Fixed `uuid` version lock.
|
||||
|
||||
|
||||
## 1.5.5 - 2019-05-23
|
||||
- Improved `Signature`.
|
||||
|
||||
|
||||
## 1.5.4 - 2019-05-22
|
||||
- Updated `Endpoints`.
|
||||
- Fixed `Content-Type` in header.
|
||||
|
||||
|
||||
## 1.5.3 - 2019-05-13
|
||||
- Improved `Endpoint` tips.
|
||||
- Improved `Endpoints` for `STS`.
|
||||
|
||||
|
||||
## 1.5.2 - 2019-05-10
|
||||
- Improved `Result` object.
|
||||
|
||||
|
||||
## 1.5.1 - 2019-05-09
|
||||
- Supported `Resolver` for Third-party dependencies.
|
||||
|
||||
|
||||
## 1.5.0 - 2019-05-07
|
||||
- Improved `Resolver` for products.
|
||||
|
||||
|
||||
## 1.4.0 - 2019-05-06
|
||||
- Support `Retry` and `Asynchronous` for Request.
|
||||
|
||||
|
||||
## 1.3.1 - 2019-04-30
|
||||
- Allow timeouts to be set in microseconds.
|
||||
|
||||
|
||||
## 1.3.0 - 2019-04-18
|
||||
- Improved parameters methods.
|
||||
- Optimized the logic for body encode.
|
||||
|
||||
|
||||
## 1.2.1 - 2019-04-11
|
||||
- Improve exception code and message for `Region ID`.
|
||||
|
||||
|
||||
## 1.2.0 - 2019-04-11
|
||||
- Improve exception message for `Region ID`.
|
||||
|
||||
|
||||
## 1.1.1 - 2019-04-02
|
||||
- Added endpoints for `batchcomputenew`, `privatelink`.
|
||||
- Improve Region ID tips.
|
||||
|
||||
|
||||
## 1.1.0 - 2019-04-01
|
||||
- Updated `composer.json`.
|
||||
|
||||
|
||||
## 1.0.27 - 2019-03-31
|
||||
- Support `Policy` for `ramRoleArnClient`.
|
||||
|
||||
|
||||
## 1.0.26 - 2019-03-27
|
||||
- Support `pid`, `cost`, `start_time` for Log.
|
||||
|
||||
|
||||
## 1.0.25 - 2019-03-27
|
||||
- Updated default log format.
|
||||
- Add endpoints for `dbs`.
|
||||
|
||||
|
||||
## 1.0.24 - 2019-03-26
|
||||
- Support Log.
|
||||
|
||||
|
||||
## 1.0.23 - 2019-03-23
|
||||
- Remove SVG.
|
||||
|
||||
|
||||
## 1.0.22 - 2019-03-20
|
||||
- Add endpoint `cn-hangzhou` for `idaas` .
|
||||
|
||||
|
||||
## 1.0.21 - 2019-03-19
|
||||
- Installing by Using the ZIP file.
|
||||
- Update Docs.
|
||||
|
||||
|
||||
## 1.0.20 - 2019-03-13
|
||||
- Improve Tests.
|
||||
- Update Docs.
|
||||
|
||||
|
||||
## 1.0.19 - 2019-03-12
|
||||
- Add SSL Verify Option `verify()`.
|
||||
|
||||
|
||||
## 1.0.18 - 2019-03-11
|
||||
- Add endpoints for `acr`.
|
||||
- Add endpoints for `faas`.
|
||||
- Add endpoints for `ehs`.
|
||||
- SSL certificates are not validated by default.
|
||||
|
||||
|
||||
## 1.0.17 - 2019-03-08
|
||||
- Support Mock for Test.
|
||||
|
||||
|
||||
## 1.0.16 - 2019-03-07
|
||||
- Support Credential Provider Chain.
|
||||
- Support `CCC`.
|
||||
- Add `ap-south-1` for `cas`.
|
||||
- Add `ap-southeast-1` for `waf`.
|
||||
- Update Docs.
|
||||
|
||||
|
||||
## 1.0.15 - 2019-02-27
|
||||
- Add endpoints for `Chatbot`.
|
||||
- Change endpoints for `drdspost` and `drdspre`.
|
||||
|
||||
|
||||
## 1.0.14 - 2019-02-21
|
||||
- Enable debug mode by set environment variable `DEBUG=sdk`.
|
||||
|
||||
|
||||
## 1.0.13 - 2019-02-18
|
||||
- Support Release Script `composer release`.
|
||||
- Add endpoints for apigateway in `drdspre` in `cn-qingdao`.
|
||||
- Add endpoints for apigateway in `drdspre` in `cn-beijing`.
|
||||
- Add endpoints for apigateway in `drdspre` in `cn-hangzhou`.
|
||||
- Add endpoints for apigateway in `drdspre` in `cn-shanghai`.
|
||||
- Add endpoints for apigateway in `drdspre` in `cn-shenzhen`.
|
||||
- Add endpoints for apigateway in `drdspre` in `cn-hongkong`.
|
||||
- Add endpoints for apigateway in `drdspost` in `ap-southeast-1`.
|
||||
- Add endpoints for apigateway in `drdspost` in `cn-shanghai`.
|
||||
- Add endpoints for apigateway in `drdspost` in `cn-hongkong`.
|
||||
- Add endpoints for apigateway in `vod` in `ap-southeast-1`.
|
||||
- Add endpoints for apigateway in `vod` in `eu-central-1`.
|
||||
|
||||
|
||||
## 1.0.12 - 2019-02-16
|
||||
- Support `open_basedir`.
|
||||
|
||||
|
||||
## 1.0.11 - 2019-02-13
|
||||
- Improve User Agent.
|
||||
|
||||
|
||||
## 1.0.10 - 2019-02-12
|
||||
- `userAgentAppend` is renamed to `appendUserAgent`.
|
||||
|
||||
|
||||
## 1.0.9 - 2019-02-12
|
||||
- `userAgent` is renamed to `userAgentAppend`.
|
||||
|
||||
|
||||
## 1.0.8 - 2019-02-11
|
||||
- `userAgent` - Support DIY User Agent.
|
||||
- Add endpoints for apigateway in Zhangjiakou.
|
||||
- Add endpoints for apigateway in Hu He Hao Te.
|
||||
- Add endpoints for vod in Hu He Hao Te.
|
||||
- Add endpoints for hsm in Zhangjiakou.
|
||||
- Add endpoints for luban in Germany.
|
||||
- Add endpoints for linkwan in Hangzhou.
|
||||
- Add endpoints for drdspost in Singapore.
|
||||
|
||||
|
||||
## 1.0.7 - 2019-01-28
|
||||
- Add endpoints for gpdb in Tokyo.
|
||||
- Add endpoints for elasticsearch in Beijing.
|
||||
|
||||
|
||||
## 1.0.6 - 2019-01-23
|
||||
- Add endpoints for dysmsapi in Singapore.
|
||||
- Add endpoints for dybaseapi.
|
||||
- Add endpoints for dyiotapi.
|
||||
- Add endpoints for dycdpapi.
|
||||
- Add endpoints for dyplsapi.
|
||||
- Add endpoints for dypnsapi.
|
||||
- Add endpoints for dyvmsapi.
|
||||
- Add endpoints for snsuapi.
|
||||
|
||||
|
||||
## 1.0.5 - 2019-01-21
|
||||
- Add endpoints for ApiGateway in Silicon Valley, Virginia.
|
||||
- Add endpoints for Image Search in Shanghai.
|
||||
|
||||
|
||||
## 1.0.4 - 2019-01-17
|
||||
- Support fixer all.
|
||||
- Add Endpoints.
|
||||
|
||||
|
||||
## 1.0.3 - 2019-01-15
|
||||
- Update Endpoints.
|
||||
- Update README.md.
|
||||
- Update Return Result Message.
|
||||
|
||||
|
||||
## 1.0.2 - 2019-01-15
|
||||
- Optimize the documentation.
|
||||
- Adjust the CI configuration.
|
||||
|
||||
|
||||
## 1.0.1 - 2019-01-09
|
||||
- Distinguish credential error.
|
||||
- Add endpoints for NLS.
|
||||
- Add not found product tip.
|
||||
|
||||
|
||||
## 1.0.0 - 2019-01-07
|
||||
- Initial release of the Alibaba Cloud Client for PHP Version 1.0.0 on Packagist See <https://github.com/aliyun/openapi-sdk-php-client> for more information.
|
||||
30
app/Common/extend/alibabacloud/client/CONTRIBUTING.md
Executable file
30
app/Common/extend/alibabacloud/client/CONTRIBUTING.md
Executable file
@@ -0,0 +1,30 @@
|
||||
# Contributing to the Alibaba Cloud Client for PHP
|
||||
|
||||
We work hard to provide a high-quality and useful SDK for Alibaba Cloud, and
|
||||
we greatly value feedback and contributions from our community. Please submit
|
||||
your [issues][issues] or [pull requests][pull-requests] through GitHub.
|
||||
|
||||
## Tips
|
||||
|
||||
- The SDK is released under the [Apache license][license]. Any code you submit
|
||||
will be released under that license. For substantial contributions, we may
|
||||
ask you to sign a [Alibaba Documentation Corporate Contributor License
|
||||
Agreement (CLA)][cla].
|
||||
- We follow all of the relevant PSR recommendations from the [PHP Framework
|
||||
Interop Group][php-fig]. Please submit code that follows these standards.
|
||||
The [PHP CS Fixer][cs-fixer] tool can be helpful for formatting your code.
|
||||
Your can use `composer fixer` to fix code.
|
||||
- We maintain a high percentage of code coverage in our unit tests. If you make
|
||||
changes to the code, please add, update, and/or remove tests as appropriate.
|
||||
- If your code does not conform to the PSR standards, does not include adequate
|
||||
tests, or does not contain a changelog document, we may ask you to update
|
||||
your pull requests before we accept them. We also reserve the right to deny
|
||||
any pull requests that do not align with our standards or goals.
|
||||
|
||||
[issues]: https://github.com/aliyun/openapi-sdk-php-client/issues
|
||||
[pull-requests]: https://github.com/aliyun/openapi-sdk-php-client/pulls
|
||||
[license]: http://www.apache.org/licenses/LICENSE-2.0
|
||||
[cla]: https://alibaba-cla-2018.oss-cn-beijing.aliyuncs.com/Alibaba_Documentation_Open_Source_Corporate_CLA.pdf
|
||||
[php-fig]: http://php-fig.org
|
||||
[cs-fixer]: http://cs.sensiolabs.org/
|
||||
[docs-readme]: https://github.com/aliyun/openapi-sdk-php-client/blob/master/README.md
|
||||
13
app/Common/extend/alibabacloud/client/LICENSE.md
Executable file
13
app/Common/extend/alibabacloud/client/LICENSE.md
Executable file
@@ -0,0 +1,13 @@
|
||||
Copyright 1999-2019 Alibaba Group Holding Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
88
app/Common/extend/alibabacloud/client/NOTICE.md
Executable file
88
app/Common/extend/alibabacloud/client/NOTICE.md
Executable file
@@ -0,0 +1,88 @@
|
||||
# Alibaba Cloud Client for PHP
|
||||
|
||||
<https://www.alibabacloud.com/>
|
||||
|
||||
Copyright 1999-2019 Alibaba Group. or its affiliates. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License").
|
||||
You may not use this file except in compliance with the License.
|
||||
A copy of the License is located at
|
||||
|
||||
<http://www.apache.org/licenses/LICENSE-2.0>
|
||||
|
||||
or in the "license" file accompanying this file. This file is distributed
|
||||
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
express or implied. See the License for the specific language governing
|
||||
permissions and limitations under the License.
|
||||
|
||||
# Guzzle
|
||||
|
||||
<https://github.com/guzzle/guzzle>
|
||||
|
||||
Copyright (c) 2011-2018 Michael Dowling, https://github.com/mtdowling <mtdowling@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
# jmespath.php
|
||||
|
||||
<https://github.com/mtdowling/jmespath.php>
|
||||
|
||||
Copyright (c) 2014 Michael Dowling, https://github.com/mtdowling
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
# Dot
|
||||
|
||||
<https://github.com/adbario/php-dot-notation>
|
||||
|
||||
Copyright (c) 2016-2019 Riku Särkinen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
161
app/Common/extend/alibabacloud/client/README-zh-CN.md
Executable file
161
app/Common/extend/alibabacloud/client/README-zh-CN.md
Executable file
@@ -0,0 +1,161 @@
|
||||
[English](/README.md) | 简体中文
|
||||
|
||||
|
||||
# Alibaba Cloud Client for PHP
|
||||
[](https://packagist.org/packages/alibabacloud/client)
|
||||
[](https://packagist.org/packages/alibabacloud/client)
|
||||
[](https://packagist.org/packages/alibabacloud/client)
|
||||
[](https://packagist.org/packages/alibabacloud/client)
|
||||
[](https://codecov.io/gh/aliyun/openapi-sdk-php-client)
|
||||
[](https://travis-ci.org/aliyun/openapi-sdk-php-client)
|
||||
[](https://ci.appveyor.com/project/aliyun/openapi-sdk-php-client/branch/master)
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||
Alibaba Cloud Client for PHP 是帮助 PHP 开发者管理凭据、发送请求的客户端工具,[Alibaba Cloud SDK for PHP][SDK] 由本工具提供底层支持。
|
||||
|
||||
|
||||
## 在线示例
|
||||
[API Explorer](https://api.aliyun.com) 提供在线调用阿里云产品,并动态生成 SDK 代码和快速检索接口等能力,能显著降低使用云 API 的难度。
|
||||
|
||||
|
||||
## 先决条件
|
||||
您的系统需要满足[先决条件](/docs/zh-CN/0-Prerequisites.md),包括 PHP> = 5.5。 我们强烈建议使用cURL扩展,并使用TLS后端编译cURL 7.16.2+。
|
||||
|
||||
|
||||
## 安装依赖
|
||||
如果已在系统上[全局安装 Composer](https://getcomposer.org/doc/00-intro.md#globally),请直接在项目目录中运行以下内容来安装 Alibaba Cloud Client for PHP 作为依赖项:
|
||||
```
|
||||
composer require alibabacloud/client
|
||||
```
|
||||
> 一些用户可能由于网络问题无法安装,可以使用[阿里云 Composer 全量镜像](https://developer.aliyun.com/composer)。
|
||||
|
||||
请看[安装](/docs/zh-CN/1-Installation.md)有关通过 Composer 和其他方式安装的详细信息。
|
||||
|
||||
|
||||
## 快速使用
|
||||
在您开始之前,您需要注册阿里云帐户并获取您的[凭证](https://usercenter.console.aliyun.com/#/manage/ak)。
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
|
||||
AlibabaCloud::accessKeyClient('accessKeyId', 'accessKeySecret')->asDefaultClient();
|
||||
```
|
||||
|
||||
## ROA 请求
|
||||
```php
|
||||
<?php
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
|
||||
try {
|
||||
$result = AlibabaCloud::roa()
|
||||
->regionId('cn-hangzhou') // 指定请求的区域,不指定则使用客户端区域、默认区域
|
||||
->product('CS') // 指定产品
|
||||
->version('2015-12-15') // 指定产品版本
|
||||
->action('DescribeClusterServices') // 指定产品接口
|
||||
->serviceCode('cs') // 设置 ServiceCode 以备寻址,非必须
|
||||
->endpointType('openAPI') // 设置类型,非必须
|
||||
->method('GET') // 指定请求方式
|
||||
->host('cs.aliyun.com') // 指定域名则不会寻址,如认证方式为 Bearer Token 的服务则需要指定
|
||||
->pathPattern('/clusters/[ClusterId]/services') // 指定ROA风格路径规则
|
||||
->withClusterId('123456') // 为路径中参数赋值,方法名:with + 参数
|
||||
->request(); // 发起请求并返回结果对象,请求需要放在设置的最后面
|
||||
|
||||
print_r($result->toArray());
|
||||
|
||||
} catch (ClientException $exception) {
|
||||
print_r($exception->getErrorMessage());
|
||||
} catch (ServerException $exception) {
|
||||
print_r($exception->getErrorMessage());
|
||||
}
|
||||
```
|
||||
|
||||
## RPC 请求
|
||||
```php
|
||||
<?php
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
|
||||
try {
|
||||
$result = AlibabaCloud::rpc()
|
||||
->product('Cdn')
|
||||
->version('2014-11-11')
|
||||
->action('DescribeCdnService')
|
||||
->method('POST')
|
||||
->request();
|
||||
|
||||
print_r($result->toArray());
|
||||
|
||||
} catch (ClientException $exception) {
|
||||
print_r($exception->getErrorMessage());
|
||||
} catch (ServerException $exception) {
|
||||
print_r($exception->getErrorMessage());
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## 文档
|
||||
* [先决条件](/docs/zh-CN/0-Prerequisites.md)
|
||||
* [安装](/docs/zh-CN/1-Installation.md)
|
||||
* [客户端](/docs/zh-CN/2-Client.md)
|
||||
* [请求](/docs/zh-CN/3-Request.md)
|
||||
* [结果](/docs/zh-CN/4-Result.md)
|
||||
* [区域](/docs/zh-CN/5-Region.md)
|
||||
* [域名](/docs/zh-CN/6-Host.md)
|
||||
* [SSL 验证](/docs/zh-CN/7-Verify.md)
|
||||
* [调试](/docs/zh-CN/8-Debug.md)
|
||||
* [日志](/docs/zh-CN/9-Log.md)
|
||||
* [测试](/docs/zh-CN/10-Test.md)
|
||||
|
||||
|
||||
## 问题
|
||||
[提交 Issue](https://github.com/aliyun/openapi-sdk-php-client/issues/new/choose),不符合指南的问题可能会立即关闭。
|
||||
|
||||
|
||||
## 发行说明
|
||||
每个版本的详细更改记录在[发行说明](/CHANGELOG.md)中。
|
||||
|
||||
|
||||
## 贡献
|
||||
提交 Pull Request 之前请阅读[贡献指南](/CONTRIBUTING.md)。
|
||||
|
||||
|
||||
## 相关
|
||||
* [阿里云服务 Regions & Endpoints][endpoints]
|
||||
* [OpenAPI Explorer][open-api]
|
||||
* [Packagist][packagist]
|
||||
* [Composer][composer]
|
||||
* [Guzzle中文文档][guzzle-docs]
|
||||
* [最新源码][latest-release]
|
||||
|
||||
|
||||
## 许可证
|
||||
[Apache-2.0](/LICENSE.md)
|
||||
|
||||
版权所有 1999-2019 阿里巴巴集团
|
||||
|
||||
|
||||
[SDK]: https://github.com/aliyun/openapi-sdk-php
|
||||
[open-api]: https://api.aliyun.com
|
||||
[latest-release]: https://github.com/aliyun/openapi-sdk-php-client
|
||||
[guzzle-docs]: https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html
|
||||
[composer]: https://getcomposer.org
|
||||
[packagist]: https://packagist.org/packages/alibabacloud/sdk
|
||||
[home]: https://home.console.aliyun.com
|
||||
[aliyun]: https://www.aliyun.com
|
||||
[regions]: https://help.aliyun.com/document_detail/40654.html
|
||||
[endpoints]: https://developer.aliyun.com/endpoints
|
||||
[cURL]: http://php.net/manual/zh/book.curl.php
|
||||
[OPCache]: http://php.net/manual/zh/book.opcache.php
|
||||
[xdebug]: http://xdebug.org
|
||||
[OpenSSL]: http://php.net/manual/zh/book.openssl.php
|
||||
[client]: https://github.com/aliyun/openapi-sdk-php-client
|
||||
170
app/Common/extend/alibabacloud/client/README.md
Executable file
170
app/Common/extend/alibabacloud/client/README.md
Executable file
@@ -0,0 +1,170 @@
|
||||
English | [简体中文](/README-zh-CN.md)
|
||||
|
||||
|
||||
<p align="center">
|
||||
<a href=" https://www.alibabacloud.com"><img src="https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg"></a>
|
||||
</p>
|
||||
|
||||
<h1 align="center">Alibaba Cloud Client for PHP</h1>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://packagist.org/packages/alibabacloud/client"><img src="https://poser.pugx.org/alibabacloud/client/v/stable" alt="Latest Stable Version"></a>
|
||||
<a href="https://packagist.org/packages/alibabacloud/client"><img src="https://poser.pugx.org/alibabacloud/client/v/unstable" alt="Latest Unstable Version"></a>
|
||||
<a href="https://packagist.org/packages/alibabacloud/client"><img src="https://poser.pugx.org/alibabacloud/client/composerlock" alt="composer.lock"></a>
|
||||
<a href="https://packagist.org/packages/alibabacloud/client"><img src="https://poser.pugx.org/alibabacloud/client/downloads" alt="Total Downloads"></a>
|
||||
<a href="https://packagist.org/packages/alibabacloud/client"><img src="https://poser.pugx.org/alibabacloud/client/license" alt="License"></a>
|
||||
<br/>
|
||||
<a href="https://codecov.io/gh/aliyun/openapi-sdk-php-client"><img src="https://codecov.io/gh/aliyun/openapi-sdk-php-client/branch/master/graph/badge.svg" alt="codecov"></a>
|
||||
<a href="https://scrutinizer-ci.com/g/aliyun/openapi-sdk-php-client"><img src="https://scrutinizer-ci.com/g/aliyun/openapi-sdk-php-client/badges/quality-score.png" alt="Scrutinizer Code Quality"></a>
|
||||
<a href="https://travis-ci.org/aliyun/openapi-sdk-php-client"><img src="https://travis-ci.org/aliyun/openapi-sdk-php-client.svg?branch=master" alt="Travis Build Status"></a>
|
||||
<a href="https://ci.appveyor.com/project/aliyun/openapi-sdk-php-client/branch/master"><img src="https://ci.appveyor.com/api/projects/status/699v083woth7mj85/branch/master?svg=true" alt="Appveyor Build Status"></a>
|
||||
<a href="https://scrutinizer-ci.com/code-intelligence"><img src="https://scrutinizer-ci.com/g/aliyun/openapi-sdk-php-client/badges/code-intelligence.svg" alt="Code Intelligence Status"></a>
|
||||
</p>
|
||||
|
||||
|
||||
Alibaba Cloud Client for PHP is a client tool that helps PHP developers manage credentials and send requests, [Alibaba Cloud SDK for PHP][SDK] dependency on this tool.
|
||||
|
||||
|
||||
## Online Demo
|
||||
[API Explorer](https://api.aliyun.com) provides the ability to call the cloud product OpenAPI online, and dynamically generate SDK Example code and quick retrieval interface, which can significantly reduce the difficulty of using the cloud API.
|
||||
|
||||
|
||||
## Prerequisites
|
||||
Your system will need to meet the [Prerequisites](/docs/en-US/0-Prerequisites.md), including having PHP >= 5.5. We highly recommend having it compiled with the cURL extension and cURL 7.16.2+.
|
||||
|
||||
|
||||
## Installation
|
||||
If Composer is already [installed globally on your system](https://getcomposer.org/doc/00-intro.md#globally), run the following in the base directory of your project to install Alibaba Cloud Client for PHP as a dependency:
|
||||
```
|
||||
composer require alibabacloud/client
|
||||
```
|
||||
> Some users may not be able to install due to network problems, you can try to switch the Composer mirror.
|
||||
|
||||
Please see the [Installation](/docs/en-US/1-Installation.md) for more detailed information about installing the Alibaba Cloud Client for PHP through Composer and other means.
|
||||
|
||||
|
||||
## Quick Examples
|
||||
Before you begin, you need to sign up for an Alibaba Cloud account and retrieve your [Credentials](https://usercenter.console.aliyun.com/#/manage/ak).
|
||||
|
||||
### Create Client
|
||||
```php
|
||||
<?php
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
|
||||
AlibabaCloud::accessKeyClient('accessKeyId', 'accessKeySecret')->asDefaultClient();
|
||||
```
|
||||
|
||||
### ROA Request
|
||||
```php
|
||||
<?php
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
|
||||
try {
|
||||
$result = AlibabaCloud::roa()
|
||||
->regionId('cn-hangzhou') // Specify the requested regionId, if not specified, use the client regionId, then default regionId
|
||||
->product('CS') // Specify product
|
||||
->version('2015-12-15') // Specify product version
|
||||
->action('DescribeClusterServices') // Specify product interface
|
||||
->serviceCode('cs') // Set ServiceCode for addressing, optional
|
||||
->endpointType('openAPI') // Set type, optional
|
||||
->method('GET') // Set request method
|
||||
->host('cs.aliyun.com') // Location Service will not be enabled if the host is specified. For example, service with a Certification type-Bearer Token should be specified
|
||||
->pathPattern('/clusters/[ClusterId]/services') // Specify path rule with ROA-style
|
||||
->withClusterId('123456') // Assign values to parameters in the path. Method: with + Parameter
|
||||
->request(); // Make a request and return to result object. The request is to be placed at the end of the setting
|
||||
|
||||
print_r($result->toArray());
|
||||
|
||||
} catch (ClientException $exception) {
|
||||
print_r($exception->getErrorMessage());
|
||||
} catch (ServerException $exception) {
|
||||
print_r($exception->getErrorMessage());
|
||||
}
|
||||
```
|
||||
|
||||
### RPC Request
|
||||
```php
|
||||
<?php
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
|
||||
try {
|
||||
$result = AlibabaCloud::rpc()
|
||||
->product('Cdn')
|
||||
->version('2014-11-11')
|
||||
->action('DescribeCdnService')
|
||||
->method('POST')
|
||||
->request();
|
||||
|
||||
print_r($result->toArray());
|
||||
|
||||
} catch (ClientException $exception) {
|
||||
print_r($exception->getErrorMessage());
|
||||
} catch (ServerException $exception) {
|
||||
print_r($exception->getErrorMessage());
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Documentation
|
||||
* [Prerequisites](/docs/en-US/0-Prerequisites.md)
|
||||
* [Installation](/docs/en-US/1-Installation.md)
|
||||
* [Client](/docs/en-US/2-Client.md)
|
||||
* [Request](/docs/en-US/3-Request.md)
|
||||
* [Result](/docs/en-US/4-Result.md)
|
||||
* [Region](/docs/en-US/5-Region.md)
|
||||
* [Host](/docs/en-US/6-Host.md)
|
||||
* [SSL Verify](/docs/en-US/7-Verify.md)
|
||||
* [Debug](/docs/en-US/8-Debug.md)
|
||||
* [Log](/docs/en-US/9-Log.md)
|
||||
* [Test](/docs/en-US/10-Test.md)
|
||||
|
||||
|
||||
## Issues
|
||||
[Opening an Issue](https://github.com/aliyun/openapi-sdk-php-client/issues/new/choose), Issues not conforming to the guidelines may be closed immediately.
|
||||
|
||||
|
||||
## Changelog
|
||||
Detailed changes for each release are documented in the [release notes](/CHANGELOG.md).
|
||||
|
||||
|
||||
## Contribution
|
||||
Please make sure to read the [Contributing Guide](/CONTRIBUTING.md) before making a pull request.
|
||||
|
||||
|
||||
## References
|
||||
* [Alibaba Cloud Regions & Endpoints][endpoints]
|
||||
* [OpenAPI Explorer][open-api]
|
||||
* [Packagist][packagist]
|
||||
* [Composer][composer]
|
||||
* [Guzzle Documentation][guzzle-docs]
|
||||
* [Latest Release][latest-release]
|
||||
|
||||
|
||||
## License
|
||||
[Apache-2.0](/LICENSE.md)
|
||||
|
||||
Copyright 1999-2019 Alibaba Group Holding Ltd.
|
||||
|
||||
|
||||
[SDK]: https://github.com/aliyun/openapi-sdk-php
|
||||
[open-api]: https://api.alibabacloud.com
|
||||
[latest-release]: https://github.com/aliyun/openapi-sdk-php-client
|
||||
[guzzle-docs]: http://docs.guzzlephp.org/en/stable/request-options.html
|
||||
[composer]: https://getcomposer.org
|
||||
[packagist]: https://packagist.org/packages/alibabacloud/sdk
|
||||
[home]: https://home.console.aliyun.com
|
||||
[alibabacloud]: https://www.alibabacloud.com
|
||||
[regions]: https://www.alibabacloud.com/help/doc-detail/40654.html
|
||||
[endpoints]: https://developer.aliyun.com/endpoints
|
||||
[cURL]: http://php.net/manual/en/book.curl.php
|
||||
[OPCache]: http://php.net/manual/en/book.opcache.php
|
||||
[xdebug]: http://xdebug.org
|
||||
[OpenSSL]: http://php.net/manual/en/book.openssl.php
|
||||
[client]: https://github.com/aliyun/openapi-sdk-php-client
|
||||
6
app/Common/extend/alibabacloud/client/UPGRADING.md
Executable file
6
app/Common/extend/alibabacloud/client/UPGRADING.md
Executable file
@@ -0,0 +1,6 @@
|
||||
Upgrading Guide
|
||||
===============
|
||||
|
||||
1.x
|
||||
-----------------------
|
||||
- This is the first version. See <https://github.com/aliyun/openapi-sdk-php-client> for more information.
|
||||
116
app/Common/extend/alibabacloud/client/composer.json
Executable file
116
app/Common/extend/alibabacloud/client/composer.json
Executable file
@@ -0,0 +1,116 @@
|
||||
{
|
||||
"name": "alibabacloud/client",
|
||||
"homepage": "https://www.alibabacloud.com/",
|
||||
"description": "Alibaba Cloud Client for PHP - Use Alibaba Cloud in your PHP project",
|
||||
"keywords": [
|
||||
"sdk",
|
||||
"tool",
|
||||
"cloud",
|
||||
"client",
|
||||
"aliyun",
|
||||
"library",
|
||||
"alibaba",
|
||||
"alibabacloud"
|
||||
],
|
||||
"type": "library",
|
||||
"license": "Apache-2.0",
|
||||
"support": {
|
||||
"source": "https://github.com/aliyun/openapi-sdk-php-client",
|
||||
"issues": "https://github.com/aliyun/openapi-sdk-php-client/issues"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alibaba Cloud SDK",
|
||||
"email": "sdk-team@alibabacloud.com",
|
||||
"homepage": "http://www.alibabacloud.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.5",
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-libxml": "*",
|
||||
"ext-openssl": "*",
|
||||
"ext-mbstring": "*",
|
||||
"ext-simplexml": "*",
|
||||
"ext-xmlwriter": "*",
|
||||
"guzzlehttp/guzzle": "^6.3",
|
||||
"danielstjules/stringy": "^3.1",
|
||||
"mtdowling/jmespath.php": "^2.4",
|
||||
"adbario/php-dot-notation": "^2.2",
|
||||
"clagiordano/weblibs-configmanager": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-spl": "*",
|
||||
"ext-dom": "*",
|
||||
"ext-pcre": "*",
|
||||
"psr/cache": "^1.0",
|
||||
"ext-sockets": "*",
|
||||
"drupal/coder": "^8.3",
|
||||
"symfony/dotenv": "^3.4",
|
||||
"league/climate": "^3.2.4",
|
||||
"phpunit/phpunit": "^4.8.35|^5.4.3",
|
||||
"monolog/monolog": "^1.24",
|
||||
"composer/composer": "^1.8",
|
||||
"mikey179/vfsstream": "^1.6",
|
||||
"symfony/var-dumper": "^3.4"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-sockets": "To use client-side monitoring"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"AlibabaCloud\\Client\\": "src"
|
||||
},
|
||||
"files": [
|
||||
"src/Functions.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"AlibabaCloud\\Client\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"preferred-install": "dist",
|
||||
"optimize-autoloader": true
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"scripts-descriptions": {
|
||||
"cs": "Tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard.",
|
||||
"cbf": "Automatically correct coding standard violations.",
|
||||
"fixer": "Fixes code to follow standards.",
|
||||
"test": "Run all tests.",
|
||||
"unit": "Run Unit tests.",
|
||||
"feature": "Run Feature tests.",
|
||||
"clearCache": "Clear cache like coverage.",
|
||||
"coverage": "Show Coverage html.",
|
||||
"endpoints": "Update endpoints from OSS."
|
||||
},
|
||||
"scripts": {
|
||||
"cs": "phpcs --standard=PSR2 -n ./",
|
||||
"cbf": "phpcbf --standard=PSR2 -n ./",
|
||||
"fixer": "php-cs-fixer fix ./",
|
||||
"test": [
|
||||
"phpunit --colors=always"
|
||||
],
|
||||
"unit": [
|
||||
"@clearCache",
|
||||
"phpunit --testsuite=Unit --colors=always"
|
||||
],
|
||||
"feature": [
|
||||
"@clearCache",
|
||||
"phpunit --testsuite=Feature --colors=always"
|
||||
],
|
||||
"coverage": "open cache/coverage/index.html",
|
||||
"clearCache": "rm -rf cache/*",
|
||||
"endpoints": [
|
||||
"AlibabaCloud\\Client\\Regions\\LocationService::updateEndpoints",
|
||||
"@fixer"
|
||||
],
|
||||
"release": [
|
||||
"AlibabaCloud\\Client\\Release::release"
|
||||
]
|
||||
}
|
||||
}
|
||||
53
app/Common/extend/alibabacloud/client/src/Accept.php
Executable file
53
app/Common/extend/alibabacloud/client/src/Accept.php
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client;
|
||||
|
||||
/**
|
||||
* Class Accept
|
||||
*
|
||||
* @package AlibabaCloud\Client
|
||||
*/
|
||||
class Accept
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $format;
|
||||
|
||||
/**
|
||||
* Accept constructor.
|
||||
*
|
||||
* @param string $format
|
||||
*/
|
||||
private function __construct($format)
|
||||
{
|
||||
$this->format = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $format
|
||||
*
|
||||
* @return Accept
|
||||
*/
|
||||
public static function create($format)
|
||||
{
|
||||
return new static($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
$key = \strtoupper($this->format);
|
||||
|
||||
$list = [
|
||||
'JSON' => 'application/json',
|
||||
'XML' => 'application/xml',
|
||||
'RAW' => 'application/octet-stream',
|
||||
'FORM' => 'application/x-www-form-urlencoded'
|
||||
];
|
||||
|
||||
return isset($list[$key]) ? $list[$key] : $list['RAW'];
|
||||
}
|
||||
}
|
||||
63
app/Common/extend/alibabacloud/client/src/AlibabaCloud.php
Executable file
63
app/Common/extend/alibabacloud/client/src/AlibabaCloud.php
Executable file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client;
|
||||
|
||||
|
||||
use AlibabaCloud\Client\Traits\LogTrait;
|
||||
use AlibabaCloud\Client\Traits\MockTrait;
|
||||
use AlibabaCloud\Client\Traits\ClientTrait;
|
||||
use AlibabaCloud\Client\Traits\HistoryTrait;
|
||||
use AlibabaCloud\Client\Traits\RequestTrait;
|
||||
use AlibabaCloud\Client\Traits\EndpointTrait;
|
||||
use AlibabaCloud\Client\Traits\DefaultRegionTrait;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class AlibabaCloud
|
||||
*
|
||||
* @package AlibabaCloud\Client
|
||||
* @mixin \AlibabaCloud\IdeHelper
|
||||
*/
|
||||
class AlibabaCloud
|
||||
{
|
||||
use ClientTrait;
|
||||
use DefaultRegionTrait;
|
||||
use EndpointTrait;
|
||||
use RequestTrait;
|
||||
use MockTrait;
|
||||
use HistoryTrait;
|
||||
use LogTrait;
|
||||
|
||||
/**
|
||||
* Version of the Client
|
||||
*/
|
||||
const VERSION = '1.5.16';
|
||||
|
||||
/**
|
||||
* This static method can directly call the specific service.
|
||||
*
|
||||
* @param string $product
|
||||
* @param array $arguments
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return object
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function __callStatic($product, $arguments)
|
||||
{
|
||||
$product = \ucfirst($product);
|
||||
|
||||
$product_class = 'AlibabaCloud' . '\\' . $product . '\\' . $product;
|
||||
|
||||
if (\class_exists($product_class)) {
|
||||
return new $product_class;
|
||||
}
|
||||
|
||||
throw new ClientException(
|
||||
"May not yet support product $product quick access, "
|
||||
. 'you can use [Alibaba Cloud Client for PHP] to send any custom '
|
||||
. 'requests: https://github.com/aliyun/openapi-sdk-php-client/blob/master/docs/en/3-Request.md',
|
||||
SDK::SERVICE_NOT_FOUND
|
||||
);
|
||||
}
|
||||
}
|
||||
30
app/Common/extend/alibabacloud/client/src/Clients/AccessKeyClient.php
Executable file
30
app/Common/extend/alibabacloud/client/src/Clients/AccessKeyClient.php
Executable file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Clients;
|
||||
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Signature\ShaHmac1Signature;
|
||||
use AlibabaCloud\Client\Credentials\AccessKeyCredential;
|
||||
|
||||
/**
|
||||
* Use the AccessKey to complete the authentication.
|
||||
*
|
||||
* @package AlibabaCloud\Client\Clients
|
||||
*/
|
||||
class AccessKeyClient extends Client
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $accessKeyId
|
||||
* @param string $accessKeySecret
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($accessKeyId, $accessKeySecret)
|
||||
{
|
||||
parent::__construct(
|
||||
new AccessKeyCredential($accessKeyId, $accessKeySecret),
|
||||
new ShaHmac1Signature()
|
||||
);
|
||||
}
|
||||
}
|
||||
29
app/Common/extend/alibabacloud/client/src/Clients/BearerTokenClient.php
Executable file
29
app/Common/extend/alibabacloud/client/src/Clients/BearerTokenClient.php
Executable file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Clients;
|
||||
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Signature\BearerTokenSignature;
|
||||
use AlibabaCloud\Client\Credentials\BearerTokenCredential;
|
||||
|
||||
/**
|
||||
* Use the Bearer Token to complete the authentication.
|
||||
*
|
||||
* @package AlibabaCloud\Client\Clients
|
||||
*/
|
||||
class BearerTokenClient extends Client
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $bearerToken
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($bearerToken)
|
||||
{
|
||||
parent::__construct(
|
||||
new BearerTokenCredential($bearerToken),
|
||||
new BearerTokenSignature()
|
||||
);
|
||||
}
|
||||
}
|
||||
72
app/Common/extend/alibabacloud/client/src/Clients/Client.php
Executable file
72
app/Common/extend/alibabacloud/client/src/Clients/Client.php
Executable file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Clients;
|
||||
|
||||
use AlibabaCloud\Client\Request\Request;
|
||||
use AlibabaCloud\Client\Traits\HttpTrait;
|
||||
use AlibabaCloud\Client\Traits\RegionTrait;
|
||||
use AlibabaCloud\Client\Credentials\StsCredential;
|
||||
use AlibabaCloud\Client\Signature\ShaHmac1Signature;
|
||||
use AlibabaCloud\Client\Signature\SignatureInterface;
|
||||
use AlibabaCloud\Client\Signature\ShaHmac256Signature;
|
||||
use AlibabaCloud\Client\Signature\BearerTokenSignature;
|
||||
use AlibabaCloud\Client\Credentials\AccessKeyCredential;
|
||||
use AlibabaCloud\Client\Credentials\CredentialsInterface;
|
||||
use AlibabaCloud\Client\Credentials\EcsRamRoleCredential;
|
||||
use AlibabaCloud\Client\Credentials\RamRoleArnCredential;
|
||||
use AlibabaCloud\Client\Credentials\RsaKeyPairCredential;
|
||||
use AlibabaCloud\Client\Credentials\BearerTokenCredential;
|
||||
use AlibabaCloud\Client\Signature\ShaHmac256WithRsaSignature;
|
||||
|
||||
/**
|
||||
* Custom Client.
|
||||
*
|
||||
* @package AlibabaCloud\Client\Clients
|
||||
*/
|
||||
class Client
|
||||
{
|
||||
use HttpTrait;
|
||||
use RegionTrait;
|
||||
use ManageTrait;
|
||||
|
||||
/**
|
||||
* @var CredentialsInterface|AccessKeyCredential|BearerTokenCredential|StsCredential|EcsRamRoleCredential|RamRoleArnCredential|RsaKeyPairCredential
|
||||
*/
|
||||
private $credential;
|
||||
|
||||
/**
|
||||
* @var SignatureInterface
|
||||
*/
|
||||
private $signature;
|
||||
|
||||
/**
|
||||
* Self constructor.
|
||||
*
|
||||
* @param CredentialsInterface $credential
|
||||
* @param SignatureInterface $signature
|
||||
*/
|
||||
public function __construct(CredentialsInterface $credential, SignatureInterface $signature)
|
||||
{
|
||||
$this->credential = $credential;
|
||||
$this->signature = $signature;
|
||||
$this->options['connect_timeout'] = Request::CONNECT_TIMEOUT;
|
||||
$this->options['timeout'] = Request::TIMEOUT;
|
||||
$this->options['verify'] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AccessKeyCredential|BearerTokenCredential|CredentialsInterface|EcsRamRoleCredential|RamRoleArnCredential|RsaKeyPairCredential|StsCredential
|
||||
*/
|
||||
public function getCredential()
|
||||
{
|
||||
return $this->credential;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SignatureInterface|BearerTokenSignature|ShaHmac1Signature|ShaHmac256Signature|ShaHmac256WithRsaSignature
|
||||
*/
|
||||
public function getSignature()
|
||||
{
|
||||
return $this->signature;
|
||||
}
|
||||
}
|
||||
26
app/Common/extend/alibabacloud/client/src/Clients/EcsRamRoleClient.php
Executable file
26
app/Common/extend/alibabacloud/client/src/Clients/EcsRamRoleClient.php
Executable file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Clients;
|
||||
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Signature\ShaHmac1Signature;
|
||||
use AlibabaCloud\Client\Credentials\EcsRamRoleCredential;
|
||||
|
||||
/**
|
||||
* Use the RAM role of an ECS instance to complete the authentication.
|
||||
*/
|
||||
class EcsRamRoleClient extends Client
|
||||
{
|
||||
/**
|
||||
* @param string $roleName
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($roleName)
|
||||
{
|
||||
parent::__construct(
|
||||
new EcsRamRoleCredential($roleName),
|
||||
new ShaHmac1Signature()
|
||||
);
|
||||
}
|
||||
}
|
||||
98
app/Common/extend/alibabacloud/client/src/Clients/ManageTrait.php
Executable file
98
app/Common/extend/alibabacloud/client/src/Clients/ManageTrait.php
Executable file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Clients;
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Filter\Filter;
|
||||
use AlibabaCloud\Client\Request\Request;
|
||||
use AlibabaCloud\Client\Credentials\StsCredential;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
use AlibabaCloud\Client\Credentials\CredentialsInterface;
|
||||
use AlibabaCloud\Client\Credentials\EcsRamRoleCredential;
|
||||
use AlibabaCloud\Client\Credentials\RamRoleArnCredential;
|
||||
use AlibabaCloud\Client\Credentials\RsaKeyPairCredential;
|
||||
use AlibabaCloud\Client\Credentials\Providers\EcsRamRoleProvider;
|
||||
use AlibabaCloud\Client\Credentials\Providers\RamRoleArnProvider;
|
||||
use AlibabaCloud\Client\Credentials\Providers\RsaKeyPairProvider;
|
||||
use AlibabaCloud\Client\Credentials\Providers\CredentialsProvider;
|
||||
|
||||
/**
|
||||
* Trait ManageTrait.
|
||||
*
|
||||
* @mixin Client
|
||||
*/
|
||||
trait ManageTrait
|
||||
{
|
||||
/**
|
||||
* @param int $timeout
|
||||
* @param int $connectTimeout
|
||||
*
|
||||
* @return CredentialsInterface|StsCredential
|
||||
*
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
public function getSessionCredential($timeout = Request::TIMEOUT, $connectTimeout = Request::CONNECT_TIMEOUT)
|
||||
{
|
||||
switch (\get_class($this->credential)) {
|
||||
case EcsRamRoleCredential::class:
|
||||
return (new EcsRamRoleProvider($this))->get();
|
||||
case RamRoleArnCredential::class:
|
||||
return (new RamRoleArnProvider($this))->get($timeout, $connectTimeout);
|
||||
case RsaKeyPairCredential::class:
|
||||
return (new RsaKeyPairProvider($this))->get($timeout, $connectTimeout);
|
||||
default:
|
||||
return $this->credential;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
* @throws ClientException
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function asGlobalClient()
|
||||
{
|
||||
return $this->asDefaultClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current client as the default client.
|
||||
*
|
||||
* @return static
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function asDefaultClient()
|
||||
{
|
||||
return $this->name(CredentialsProvider::getDefaultName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Naming clients.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return static
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function name($name)
|
||||
{
|
||||
Filter::name($name);
|
||||
|
||||
return AlibabaCloud::set($name, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isDebug()
|
||||
{
|
||||
if (isset($this->options['debug'])) {
|
||||
return $this->options['debug'] === true && PHP_SAPI === 'cli';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
33
app/Common/extend/alibabacloud/client/src/Clients/RamRoleArnClient.php
Executable file
33
app/Common/extend/alibabacloud/client/src/Clients/RamRoleArnClient.php
Executable file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Clients;
|
||||
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Signature\ShaHmac1Signature;
|
||||
use AlibabaCloud\Client\Credentials\RamRoleArnCredential;
|
||||
|
||||
/**
|
||||
* Use the AssumeRole of the RAM account to complete the authentication.
|
||||
*
|
||||
* @package AlibabaCloud\Client\Clients
|
||||
*/
|
||||
class RamRoleArnClient extends Client
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $accessKeyId
|
||||
* @param string $accessKeySecret
|
||||
* @param string $roleArn
|
||||
* @param string $roleSessionName
|
||||
* @param string|array $policy
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($accessKeyId, $accessKeySecret, $roleArn, $roleSessionName, $policy = '')
|
||||
{
|
||||
parent::__construct(
|
||||
new RamRoleArnCredential($accessKeyId, $accessKeySecret, $roleArn, $roleSessionName, $policy),
|
||||
new ShaHmac1Signature()
|
||||
);
|
||||
}
|
||||
}
|
||||
30
app/Common/extend/alibabacloud/client/src/Clients/RsaKeyPairClient.php
Executable file
30
app/Common/extend/alibabacloud/client/src/Clients/RsaKeyPairClient.php
Executable file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Clients;
|
||||
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Signature\ShaHmac1Signature;
|
||||
use AlibabaCloud\Client\Credentials\RsaKeyPairCredential;
|
||||
|
||||
/**
|
||||
* Use the RSA key pair to complete the authentication (supported only on Japanese site)
|
||||
*
|
||||
* @package AlibabaCloud\Client\Clients
|
||||
*/
|
||||
class RsaKeyPairClient extends Client
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $publicKeyId
|
||||
* @param string $privateKeyFile
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($publicKeyId, $privateKeyFile)
|
||||
{
|
||||
parent::__construct(
|
||||
new RsaKeyPairCredential($publicKeyId, $privateKeyFile),
|
||||
new ShaHmac1Signature()
|
||||
);
|
||||
}
|
||||
}
|
||||
28
app/Common/extend/alibabacloud/client/src/Clients/StsClient.php
Executable file
28
app/Common/extend/alibabacloud/client/src/Clients/StsClient.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Clients;
|
||||
|
||||
use AlibabaCloud\Client\Credentials\StsCredential;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Signature\ShaHmac1Signature;
|
||||
|
||||
/**
|
||||
* Use the STS Token to complete the authentication.
|
||||
*/
|
||||
class StsClient extends Client
|
||||
{
|
||||
/**
|
||||
* @param string $accessKeyId Access key ID
|
||||
* @param string $accessKeySecret Access Key Secret
|
||||
* @param string $securityToken Security Token
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($accessKeyId, $accessKeySecret, $securityToken = '')
|
||||
{
|
||||
parent::__construct(
|
||||
new StsCredential($accessKeyId, $accessKeySecret, $securityToken),
|
||||
new ShaHmac1Signature()
|
||||
);
|
||||
}
|
||||
}
|
||||
62
app/Common/extend/alibabacloud/client/src/Config/Config.php
Executable file
62
app/Common/extend/alibabacloud/client/src/Config/Config.php
Executable file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Config;
|
||||
|
||||
use Exception;
|
||||
use clagiordano\weblibs\configmanager\ConfigManager;
|
||||
|
||||
/**
|
||||
* Class Config
|
||||
*
|
||||
* @package AlibabaCloud\Client\Config
|
||||
*/
|
||||
class Config
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ConfigManager|null
|
||||
*/
|
||||
private static $configManager;
|
||||
|
||||
/**
|
||||
* @param string $configPath
|
||||
*
|
||||
* @param string|null $defaultValue
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($configPath, $defaultValue = null)
|
||||
{
|
||||
return self::getConfigManager()
|
||||
->getValue(
|
||||
\strtolower($configPath),
|
||||
$defaultValue
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ConfigManager
|
||||
*/
|
||||
private static function getConfigManager()
|
||||
{
|
||||
if (!self::$configManager instanceof ConfigManager) {
|
||||
self::$configManager = new ConfigManager(__DIR__ . DIRECTORY_SEPARATOR . 'Data.php');
|
||||
}
|
||||
|
||||
return self::$configManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $configPath
|
||||
* @param mixed $newValue
|
||||
*
|
||||
* @return ConfigManager
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function set($configPath, $newValue)
|
||||
{
|
||||
self::getConfigManager()->setValue(\strtolower($configPath), $newValue);
|
||||
|
||||
return self::getConfigManager()->saveConfigFile();
|
||||
}
|
||||
}
|
||||
2429
app/Common/extend/alibabacloud/client/src/Config/Data.php
Executable file
2429
app/Common/extend/alibabacloud/client/src/Config/Data.php
Executable file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials;
|
||||
|
||||
use AlibabaCloud\Client\Filter\CredentialFilter;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Use the AccessKey to complete the authentication.
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials
|
||||
*/
|
||||
class AccessKeyCredential implements CredentialsInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $accessKeyId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $accessKeySecret;
|
||||
|
||||
/**
|
||||
* AccessKeyCredential constructor.
|
||||
*
|
||||
* @param string $accessKeyId Access key ID
|
||||
* @param string $accessKeySecret Access Key Secret
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($accessKeyId, $accessKeySecret)
|
||||
{
|
||||
CredentialFilter::AccessKey($accessKeyId, $accessKeySecret);
|
||||
|
||||
$this->accessKeyId = $accessKeyId;
|
||||
$this->accessKeySecret = $accessKeySecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessKeyId()
|
||||
{
|
||||
return $this->accessKeyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessKeySecret()
|
||||
{
|
||||
return $this->accessKeySecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return "$this->accessKeyId#$this->accessKeySecret";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials;
|
||||
|
||||
use AlibabaCloud\Client\Filter\CredentialFilter;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class BearerTokenCredential
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials
|
||||
*/
|
||||
class BearerTokenCredential implements CredentialsInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $bearerToken;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param string $bearerToken
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($bearerToken)
|
||||
{
|
||||
CredentialFilter::bearerToken($bearerToken);
|
||||
|
||||
$this->bearerToken = $bearerToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBearerToken()
|
||||
{
|
||||
return $this->bearerToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessKeyId()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessKeySecret()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return "bearerToken#$this->bearerToken";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials;
|
||||
|
||||
/**
|
||||
* interface CredentialsInterface
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
interface CredentialsInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString();
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials;
|
||||
|
||||
use AlibabaCloud\Client\Filter\CredentialFilter;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Use the RAM role of an ECS instance to complete the authentication.
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials
|
||||
*/
|
||||
class EcsRamRoleCredential implements CredentialsInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $roleName;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param string $roleName
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($roleName)
|
||||
{
|
||||
CredentialFilter::roleName($roleName);
|
||||
|
||||
$this->roleName = $roleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRoleName()
|
||||
{
|
||||
return $this->roleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return "roleName#$this->roleName";
|
||||
}
|
||||
}
|
||||
181
app/Common/extend/alibabacloud/client/src/Credentials/Ini/CreateTrait.php
Executable file
181
app/Common/extend/alibabacloud/client/src/Credentials/Ini/CreateTrait.php
Executable file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials\Ini;
|
||||
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\Clients\Client;
|
||||
use AlibabaCloud\Client\Clients\AccessKeyClient;
|
||||
use AlibabaCloud\Client\Clients\RamRoleArnClient;
|
||||
use AlibabaCloud\Client\Clients\RsaKeyPairClient;
|
||||
use AlibabaCloud\Client\Clients\EcsRamRoleClient;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Clients\BearerTokenClient;
|
||||
|
||||
/**
|
||||
* Trait CreateTrait
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials\Ini
|
||||
*
|
||||
* @mixin IniCredential
|
||||
*/
|
||||
trait CreateTrait
|
||||
{
|
||||
/**
|
||||
* @param string $clientName
|
||||
* @param array $credential
|
||||
*
|
||||
* @return Client|bool
|
||||
* @throws ClientException
|
||||
*/
|
||||
protected function createClient($clientName, array $credential)
|
||||
{
|
||||
if (!isset($credential['enable']) || !$credential['enable']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isset($credential['type'])) {
|
||||
$this->missingRequired('type', $clientName);
|
||||
}
|
||||
|
||||
return $this->createClientByType($clientName, $credential)->name($clientName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $clientName
|
||||
* @param array $credential
|
||||
*
|
||||
* @return AccessKeyClient|BearerTokenClient|EcsRamRoleClient|RamRoleArnClient|RsaKeyPairClient
|
||||
* @throws ClientException
|
||||
*/
|
||||
private function createClientByType($clientName, array $credential)
|
||||
{
|
||||
switch (\strtolower($credential['type'])) {
|
||||
case 'access_key':
|
||||
return $this->accessKeyClient($clientName, $credential);
|
||||
case 'ecs_ram_role':
|
||||
return $this->ecsRamRoleClient($clientName, $credential);
|
||||
case 'ram_role_arn':
|
||||
return $this->ramRoleArnClient($clientName, $credential);
|
||||
case 'bearer_token':
|
||||
return $this->bearerTokenClient($clientName, $credential);
|
||||
case 'rsa_key_pair':
|
||||
return $this->rsaKeyPairClient($clientName, $credential);
|
||||
default:
|
||||
throw new ClientException(
|
||||
"Invalid type '{$credential['type']}' for '$clientName' in {$this->filename}",
|
||||
SDK::INVALID_CREDENTIAL
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $credential
|
||||
* @param string $clientName
|
||||
*
|
||||
* @return AccessKeyClient
|
||||
* @throws ClientException
|
||||
*/
|
||||
private function accessKeyClient($clientName, array $credential)
|
||||
{
|
||||
if (!isset($credential['access_key_id'])) {
|
||||
$this->missingRequired('access_key_id', $clientName);
|
||||
}
|
||||
|
||||
if (!isset($credential['access_key_secret'])) {
|
||||
$this->missingRequired('access_key_secret', $clientName);
|
||||
}
|
||||
|
||||
return new AccessKeyClient(
|
||||
$credential['access_key_id'],
|
||||
$credential['access_key_secret']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $clientName
|
||||
* @param array $credential
|
||||
*
|
||||
* @return EcsRamRoleClient
|
||||
* @throws ClientException
|
||||
*/
|
||||
private function ecsRamRoleClient($clientName, array $credential)
|
||||
{
|
||||
if (!isset($credential['role_name'])) {
|
||||
$this->missingRequired('role_name', $clientName);
|
||||
}
|
||||
|
||||
return new EcsRamRoleClient($credential['role_name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $clientName
|
||||
* @param array $credential
|
||||
*
|
||||
* @return RamRoleArnClient
|
||||
* @throws ClientException
|
||||
*/
|
||||
private function ramRoleArnClient($clientName, array $credential)
|
||||
{
|
||||
if (!isset($credential['access_key_id'])) {
|
||||
$this->missingRequired('access_key_id', $clientName);
|
||||
}
|
||||
|
||||
if (!isset($credential['access_key_secret'])) {
|
||||
$this->missingRequired('access_key_secret', $clientName);
|
||||
}
|
||||
|
||||
if (!isset($credential['role_arn'])) {
|
||||
$this->missingRequired('role_arn', $clientName);
|
||||
}
|
||||
|
||||
if (!isset($credential['role_session_name'])) {
|
||||
$this->missingRequired('role_session_name', $clientName);
|
||||
}
|
||||
|
||||
return new RamRoleArnClient(
|
||||
$credential['access_key_id'],
|
||||
$credential['access_key_secret'],
|
||||
$credential['role_arn'],
|
||||
$credential['role_session_name']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $clientName
|
||||
* @param array $credential
|
||||
*
|
||||
* @return BearerTokenClient
|
||||
* @throws ClientException
|
||||
*/
|
||||
private function bearerTokenClient($clientName, array $credential)
|
||||
{
|
||||
if (!isset($credential['bearer_token'])) {
|
||||
$this->missingRequired('bearer_token', $clientName);
|
||||
}
|
||||
|
||||
return new BearerTokenClient($credential['bearer_token']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $credential
|
||||
* @param string $clientName
|
||||
*
|
||||
* @return RsaKeyPairClient
|
||||
* @throws ClientException
|
||||
*/
|
||||
private function rsaKeyPairClient($clientName, array $credential)
|
||||
{
|
||||
if (!isset($credential['public_key_id'])) {
|
||||
$this->missingRequired('public_key_id', $clientName);
|
||||
}
|
||||
|
||||
if (!isset($credential['private_key_file'])) {
|
||||
$this->missingRequired('private_key_file', $clientName);
|
||||
}
|
||||
|
||||
return new RsaKeyPairClient(
|
||||
$credential['public_key_id'],
|
||||
$credential['private_key_file']
|
||||
);
|
||||
}
|
||||
}
|
||||
209
app/Common/extend/alibabacloud/client/src/Credentials/Ini/IniCredential.php
Executable file
209
app/Common/extend/alibabacloud/client/src/Credentials/Ini/IniCredential.php
Executable file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials\Ini;
|
||||
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\Clients\Client;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class IniCredential
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials\Ini
|
||||
*/
|
||||
class IniCredential
|
||||
{
|
||||
use CreateTrait;
|
||||
use OptionsTrait;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $hasLoaded;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $filename;
|
||||
|
||||
/**
|
||||
* IniCredential constructor.
|
||||
*
|
||||
* @param string $filename
|
||||
*/
|
||||
public function __construct($filename = '')
|
||||
{
|
||||
$this->filename = $filename ?: $this->getDefaultFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default credential file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultFile()
|
||||
{
|
||||
return self::getHomeDirectory() . DIRECTORY_SEPARATOR . '.alibabacloud' . DIRECTORY_SEPARATOR . 'credentials';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the environment's HOME directory.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
private static function getHomeDirectory()
|
||||
{
|
||||
if (getenv('HOME')) {
|
||||
return getenv('HOME');
|
||||
}
|
||||
|
||||
return (getenv('HOMEDRIVE') && getenv('HOMEPATH'))
|
||||
? getenv('HOMEDRIVE') . getenv('HOMEPATH')
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear credential cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function forgetLoadedCredentialsFile()
|
||||
{
|
||||
self::$hasLoaded = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the credential file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFilename()
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isNotEmpty(array $array, $key)
|
||||
{
|
||||
return isset($array[$key]) && !empty($array[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $clientName
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function missingRequired($key, $clientName)
|
||||
{
|
||||
throw new ClientException(
|
||||
"Missing required '$key' option for '$clientName' in " . $this->getFilename(),
|
||||
SDK::INVALID_CREDENTIAL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
// If it has been loaded, assign the client directly.
|
||||
if (isset(self::$hasLoaded[$this->filename])) {
|
||||
/**
|
||||
* @var $client Client
|
||||
*/
|
||||
foreach (self::$hasLoaded[$this->filename] as $projectName => $client) {
|
||||
$client->name($projectName);
|
||||
}
|
||||
|
||||
return self::$hasLoaded[$this->filename];
|
||||
}
|
||||
|
||||
return $this->loadFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exceptions will be thrown if the file is unreadable and not the default file.
|
||||
*
|
||||
* @return array|mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
private function loadFile()
|
||||
{
|
||||
if (!\AlibabaCloud\Client\inOpenBasedir($this->filename)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!\is_readable($this->filename) || !\is_file($this->filename)) {
|
||||
if ($this->filename === $this->getDefaultFile()) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return [];
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
throw new ClientException(
|
||||
'Credential file is not readable: ' . $this->getFilename(),
|
||||
SDK::INVALID_CREDENTIAL
|
||||
);
|
||||
}
|
||||
|
||||
return $this->parseFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the ini file into an array.
|
||||
*
|
||||
* @return array|mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
private function parseFile()
|
||||
{
|
||||
try {
|
||||
$file = \parse_ini_file($this->filename, true);
|
||||
if (\is_array($file) && $file !== []) {
|
||||
return $this->initClients($file);
|
||||
}
|
||||
throw new ClientException(
|
||||
'Format error: ' . $this->getFilename(),
|
||||
SDK::INVALID_CREDENTIAL
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw new ClientException(
|
||||
$e->getMessage(),
|
||||
SDK::INVALID_CREDENTIAL,
|
||||
$e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize clients.
|
||||
*
|
||||
* @param array $array
|
||||
*
|
||||
* @return array|mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
private function initClients($array)
|
||||
{
|
||||
foreach (\array_change_key_case($array) as $clientName => $configures) {
|
||||
$configures = \array_change_key_case($configures);
|
||||
$clientInstance = $this->createClient($clientName, $configures);
|
||||
if ($clientInstance instanceof Client) {
|
||||
self::$hasLoaded[$this->filename][$clientName] = $clientInstance;
|
||||
self::setClientAttributes($configures, $clientInstance);
|
||||
self::setCert($configures, $clientInstance);
|
||||
self::setProxy($configures, $clientInstance);
|
||||
}
|
||||
}
|
||||
|
||||
return isset(self::$hasLoaded[$this->filename])
|
||||
? self::$hasLoaded[$this->filename]
|
||||
: [];
|
||||
}
|
||||
}
|
||||
111
app/Common/extend/alibabacloud/client/src/Credentials/Ini/OptionsTrait.php
Executable file
111
app/Common/extend/alibabacloud/client/src/Credentials/Ini/OptionsTrait.php
Executable file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials\Ini;
|
||||
|
||||
use AlibabaCloud\Client\Clients\Client;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Trait OptionsTrait
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials\Ini
|
||||
*
|
||||
* @mixin IniCredential
|
||||
*/
|
||||
trait OptionsTrait
|
||||
{
|
||||
/**
|
||||
* @param array $configures
|
||||
* @param Client $client
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
private static function setClientAttributes($configures, Client $client)
|
||||
{
|
||||
if (self::isNotEmpty($configures, 'region_id')) {
|
||||
$client->regionId($configures['region_id']);
|
||||
}
|
||||
|
||||
if (isset($configures['debug'])) {
|
||||
$client->options(
|
||||
[
|
||||
'debug' => (bool)$configures['debug'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (self::isNotEmpty($configures, 'timeout')) {
|
||||
$client->options(
|
||||
[
|
||||
'timeout' => $configures['timeout'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (self::isNotEmpty($configures, 'connect_timeout')) {
|
||||
$client->options(
|
||||
[
|
||||
'connect_timeout' => $configures['connect_timeout'],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $configures
|
||||
* @param Client $client
|
||||
*/
|
||||
private static function setProxy($configures, Client $client)
|
||||
{
|
||||
if (self::isNotEmpty($configures, 'proxy')) {
|
||||
$client->options(
|
||||
[
|
||||
'proxy' => $configures['proxy'],
|
||||
]
|
||||
);
|
||||
}
|
||||
$proxy = [];
|
||||
if (self::isNotEmpty($configures, 'proxy_http')) {
|
||||
$proxy['http'] = $configures['proxy_http'];
|
||||
}
|
||||
if (self::isNotEmpty($configures, 'proxy_https')) {
|
||||
$proxy['https'] = $configures['proxy_https'];
|
||||
}
|
||||
if (self::isNotEmpty($configures, 'proxy_no')) {
|
||||
$proxy['no'] = \explode(',', $configures['proxy_no']);
|
||||
}
|
||||
if ($proxy !== []) {
|
||||
$client->options(
|
||||
[
|
||||
'proxy' => $proxy,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $configures
|
||||
* @param Client $client
|
||||
*/
|
||||
private static function setCert($configures, Client $client)
|
||||
{
|
||||
if (self::isNotEmpty($configures, 'cert_file') && !self::isNotEmpty($configures, 'cert_password')) {
|
||||
$client->options(
|
||||
[
|
||||
'cert' => $configures['cert_file'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (self::isNotEmpty($configures, 'cert_file') && self::isNotEmpty($configures, 'cert_password')) {
|
||||
$client->options(
|
||||
[
|
||||
'cert' => [
|
||||
$configures['cert_file'],
|
||||
$configures['cert_password'],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials\Providers;
|
||||
|
||||
use Closure;
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class CredentialsProvider
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials\Providers
|
||||
*/
|
||||
class CredentialsProvider
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $customChains;
|
||||
|
||||
/**
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function chain()
|
||||
{
|
||||
$providers = func_get_args();
|
||||
|
||||
if (empty($providers)) {
|
||||
throw new ClientException('No providers in chain', SDK::INVALID_ARGUMENT);
|
||||
}
|
||||
|
||||
foreach ($providers as $provider) {
|
||||
if (!$provider instanceof Closure) {
|
||||
throw new ClientException('Providers must all be Closures', SDK::INVALID_ARGUMENT);
|
||||
}
|
||||
}
|
||||
|
||||
self::$customChains = $providers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forget the custom providers chain.
|
||||
*/
|
||||
public static function flush()
|
||||
{
|
||||
self::$customChains = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasCustomChain()
|
||||
{
|
||||
return (bool)self::$customChains;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $clientName
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function customProvider($clientName)
|
||||
{
|
||||
foreach (self::$customChains as $provider) {
|
||||
$provider();
|
||||
if (AlibabaCloud::has($clientName)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $clientName
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function defaultProvider($clientName)
|
||||
{
|
||||
$providers = [
|
||||
self::env(),
|
||||
self::ini(),
|
||||
self::instance(),
|
||||
];
|
||||
|
||||
foreach ($providers as $provider) {
|
||||
$provider();
|
||||
if (AlibabaCloud::has($clientName)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Closure
|
||||
*/
|
||||
public static function env()
|
||||
{
|
||||
return static function () {
|
||||
$accessKeyId = \AlibabaCloud\Client\envNotEmpty('ALIBABA_CLOUD_ACCESS_KEY_ID');
|
||||
$accessKeySecret = \AlibabaCloud\Client\envNotEmpty('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
|
||||
|
||||
if ($accessKeyId && $accessKeySecret) {
|
||||
AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret)->asDefaultClient();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Closure
|
||||
*/
|
||||
public static function ini()
|
||||
{
|
||||
return static function () {
|
||||
$ini = \AlibabaCloud\Client\envNotEmpty('ALIBABA_CLOUD_CREDENTIALS_FILE');
|
||||
|
||||
if ($ini) {
|
||||
AlibabaCloud::load($ini);
|
||||
} else {
|
||||
// @codeCoverageIgnoreStart
|
||||
AlibabaCloud::load();
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
self::compatibleWithGlobal();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* Compatible with global
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
private static function compatibleWithGlobal()
|
||||
{
|
||||
if (AlibabaCloud::has('global') && !AlibabaCloud::has(self::getDefaultName())) {
|
||||
AlibabaCloud::get('global')->name(self::getDefaultName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|false|string
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function getDefaultName()
|
||||
{
|
||||
$name = \AlibabaCloud\Client\envNotEmpty('ALIBABA_CLOUD_PROFILE');
|
||||
|
||||
if ($name) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
return 'default';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Closure
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
return static function () {
|
||||
$instance = \AlibabaCloud\Client\envNotEmpty('ALIBABA_CLOUD_ECS_METADATA');
|
||||
if ($instance) {
|
||||
AlibabaCloud::ecsRamRoleClient($instance)->asDefaultClient();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials\Providers;
|
||||
|
||||
use Exception;
|
||||
use Stringy\Stringy;
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\Result\Result;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use AlibabaCloud\Client\Request\RpcRequest;
|
||||
use AlibabaCloud\Client\Credentials\StsCredential;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
use AlibabaCloud\Client\Credentials\EcsRamRoleCredential;
|
||||
|
||||
/**
|
||||
* Class EcsRamRoleProvider
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials\Providers
|
||||
*/
|
||||
class EcsRamRoleProvider extends Provider
|
||||
{
|
||||
|
||||
/**
|
||||
* Expiration time slot for temporary security credentials.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
protected $expirationSlot = 10;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $uri = 'http://100.100.100.200/latest/meta-data/ram/security-credentials/';
|
||||
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
* @return StsCredential
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$result = $this->getCredentialsInCache();
|
||||
|
||||
if ($result === null) {
|
||||
$result = $this->request();
|
||||
|
||||
if (!isset($result['AccessKeyId'], $result['AccessKeySecret'], $result['SecurityToken'])) {
|
||||
throw new ServerException($result, $this->error, SDK::INVALID_CREDENTIAL);
|
||||
}
|
||||
|
||||
$this->cache($result->toArray());
|
||||
}
|
||||
|
||||
return new StsCredential(
|
||||
$result['AccessKeyId'],
|
||||
$result['AccessKeySecret'],
|
||||
$result['SecurityToken']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credentials by request.
|
||||
*
|
||||
* @return Result
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
public function request()
|
||||
{
|
||||
$result = $this->getResponse();
|
||||
|
||||
if ($result->getStatusCode() === 404) {
|
||||
$message = 'The role was not found in the instance';
|
||||
throw new ClientException($message, SDK::INVALID_CREDENTIAL);
|
||||
}
|
||||
|
||||
if (!$result->isSuccess()) {
|
||||
$message = 'Error retrieving credentials from result';
|
||||
throw new ServerException($result, $message, SDK::INVALID_CREDENTIAL);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data from meta.
|
||||
*
|
||||
* @return mixed|ResponseInterface
|
||||
* @throws ClientException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
/**
|
||||
* @var EcsRamRoleCredential $credential
|
||||
*/
|
||||
$credential = $this->client->getCredential();
|
||||
$url = $this->uri . $credential->getRoleName();
|
||||
|
||||
$options = [
|
||||
'http_errors' => false,
|
||||
'timeout' => 1,
|
||||
'connect_timeout' => 1,
|
||||
'debug' => $this->client->isDebug(),
|
||||
];
|
||||
|
||||
try {
|
||||
return RpcRequest::createClient()->request('GET', $url, $options);
|
||||
} catch (GuzzleException $exception) {
|
||||
if (Stringy::create($exception->getMessage())->contains('timed')) {
|
||||
$message = 'Timeout or instance does not belong to Alibaba Cloud';
|
||||
} else {
|
||||
$message = $exception->getMessage();
|
||||
}
|
||||
|
||||
throw new ClientException(
|
||||
$message,
|
||||
SDK::SERVER_UNREACHABLE,
|
||||
$exception
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
88
app/Common/extend/alibabacloud/client/src/Credentials/Providers/Provider.php
Executable file
88
app/Common/extend/alibabacloud/client/src/Credentials/Providers/Provider.php
Executable file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Client\Clients\Client;
|
||||
|
||||
/**
|
||||
* Class Provider
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials\Providers
|
||||
*/
|
||||
class Provider
|
||||
{
|
||||
/**
|
||||
* For TSC Duration Seconds
|
||||
*/
|
||||
const DURATION_SECONDS = 3600;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $credentialsCache = [];
|
||||
|
||||
/**
|
||||
* Expiration time slot for temporary security credentials.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $expirationSlot = 180;
|
||||
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'Result contains no credentials';
|
||||
|
||||
/**
|
||||
* CredentialTrait constructor.
|
||||
*
|
||||
* @param Client $client
|
||||
*/
|
||||
public function __construct(Client $client)
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the credentials from the cache in the validity period.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getCredentialsInCache()
|
||||
{
|
||||
if (isset(self::$credentialsCache[$this->key()])) {
|
||||
$result = self::$credentialsCache[$this->key()];
|
||||
if (\strtotime($result['Expiration']) - \time() >= $this->expirationSlot) {
|
||||
return $result;
|
||||
}
|
||||
unset(self::$credentialsCache[$this->key()]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the toString of the credentials as the key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function key()
|
||||
{
|
||||
return (string)$this->client->getCredential();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache credentials.
|
||||
*
|
||||
* @param array $credential
|
||||
*/
|
||||
protected function cache(array $credential)
|
||||
{
|
||||
self::$credentialsCache[$this->key()] = $credential;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Result\Result;
|
||||
use AlibabaCloud\Client\Request\Request;
|
||||
use AlibabaCloud\Client\Credentials\StsCredential;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
use AlibabaCloud\Client\Credentials\Requests\AssumeRole;
|
||||
|
||||
/**
|
||||
* Class RamRoleArnProvider
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials\Providers
|
||||
*/
|
||||
class RamRoleArnProvider extends Provider
|
||||
{
|
||||
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
*
|
||||
* @param int $timeout
|
||||
* @param int $connectTimeout
|
||||
*
|
||||
* @return StsCredential
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
public function get($timeout = Request::TIMEOUT, $connectTimeout = Request::CONNECT_TIMEOUT)
|
||||
{
|
||||
$credential = $this->getCredentialsInCache();
|
||||
|
||||
if (null === $credential) {
|
||||
$result = $this->request($timeout, $connectTimeout);
|
||||
|
||||
if (!isset($result['Credentials']['AccessKeyId'],
|
||||
$result['Credentials']['AccessKeySecret'],
|
||||
$result['Credentials']['SecurityToken'])) {
|
||||
throw new ServerException($result, $this->error, SDK::INVALID_CREDENTIAL);
|
||||
}
|
||||
|
||||
$credential = $result['Credentials'];
|
||||
$this->cache($credential);
|
||||
}
|
||||
|
||||
return new StsCredential(
|
||||
$credential['AccessKeyId'],
|
||||
$credential['AccessKeySecret'],
|
||||
$credential['SecurityToken']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credentials by request.
|
||||
*
|
||||
* @param $timeout
|
||||
* @param $connectTimeout
|
||||
*
|
||||
* @return Result
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
private function request($timeout, $connectTimeout)
|
||||
{
|
||||
$clientName = __CLASS__ . \uniqid('ak', true);
|
||||
$credential = $this->client->getCredential();
|
||||
|
||||
AlibabaCloud::accessKeyClient(
|
||||
$credential->getAccessKeyId(),
|
||||
$credential->getAccessKeySecret()
|
||||
)->name($clientName);
|
||||
|
||||
return (new AssumeRole($credential))
|
||||
->client($clientName)
|
||||
->timeout($timeout)
|
||||
->connectTimeout($connectTimeout)
|
||||
->debug($this->client->isDebug())
|
||||
->request();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Result\Result;
|
||||
use AlibabaCloud\Client\Request\Request;
|
||||
use AlibabaCloud\Client\Credentials\StsCredential;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
use AlibabaCloud\Client\Credentials\AccessKeyCredential;
|
||||
use AlibabaCloud\Client\Signature\ShaHmac256WithRsaSignature;
|
||||
use AlibabaCloud\Client\Credentials\Requests\GenerateSessionAccessKey;
|
||||
|
||||
/**
|
||||
* Class RsaKeyPairProvider
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials\Providers
|
||||
*/
|
||||
class RsaKeyPairProvider extends Provider
|
||||
{
|
||||
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
* @param int $timeout
|
||||
* @param int $connectTimeout
|
||||
*
|
||||
* @return StsCredential
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
public function get($timeout = Request::TIMEOUT, $connectTimeout = Request::CONNECT_TIMEOUT)
|
||||
{
|
||||
$credential = $this->getCredentialsInCache();
|
||||
|
||||
if ($credential === null) {
|
||||
$result = $this->request($timeout, $connectTimeout);
|
||||
|
||||
if (!isset($result['SessionAccessKey']['SessionAccessKeyId'],
|
||||
$result['SessionAccessKey']['SessionAccessKeySecret'])) {
|
||||
throw new ServerException($result, $this->error, SDK::INVALID_CREDENTIAL);
|
||||
}
|
||||
|
||||
$credential = $result['SessionAccessKey'];
|
||||
$this->cache($credential);
|
||||
}
|
||||
|
||||
return new StsCredential(
|
||||
$credential['SessionAccessKeyId'],
|
||||
$credential['SessionAccessKeySecret']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credentials by request.
|
||||
*
|
||||
* @param $timeout
|
||||
* @param $connectTimeout
|
||||
*
|
||||
* @return Result
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
private function request($timeout, $connectTimeout)
|
||||
{
|
||||
$clientName = __CLASS__ . \uniqid('rsa', true);
|
||||
$credential = $this->client->getCredential();
|
||||
|
||||
AlibabaCloud::client(
|
||||
new AccessKeyCredential(
|
||||
$credential->getPublicKeyId(),
|
||||
$credential->getPrivateKey()
|
||||
),
|
||||
new ShaHmac256WithRsaSignature()
|
||||
)->name($clientName);
|
||||
|
||||
return (new GenerateSessionAccessKey($credential->getPublicKeyId()))
|
||||
->client($clientName)
|
||||
->timeout($timeout)
|
||||
->connectTimeout($connectTimeout)
|
||||
->debug($this->client->isDebug())
|
||||
->request();
|
||||
}
|
||||
}
|
||||
110
app/Common/extend/alibabacloud/client/src/Credentials/RamRoleArnCredential.php
Executable file
110
app/Common/extend/alibabacloud/client/src/Credentials/RamRoleArnCredential.php
Executable file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials;
|
||||
|
||||
use AlibabaCloud\Client\Filter\CredentialFilter;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Use the AssumeRole of the RAM account to complete the authentication.
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials
|
||||
*/
|
||||
class RamRoleArnCredential implements CredentialsInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $accessKeyId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $accessKeySecret;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $roleArn;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $roleSessionName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $policy;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param string $accessKeyId
|
||||
* @param string $accessKeySecret
|
||||
* @param string $roleArn
|
||||
* @param string $roleSessionName
|
||||
* @param string|array $policy
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($accessKeyId, $accessKeySecret, $roleArn, $roleSessionName, $policy = '')
|
||||
{
|
||||
CredentialFilter::AccessKey($accessKeyId, $accessKeySecret);
|
||||
|
||||
$this->accessKeyId = $accessKeyId;
|
||||
$this->accessKeySecret = $accessKeySecret;
|
||||
$this->roleArn = $roleArn;
|
||||
$this->roleSessionName = $roleSessionName;
|
||||
$this->policy = $policy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessKeyId()
|
||||
{
|
||||
return $this->accessKeyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessKeySecret()
|
||||
{
|
||||
return $this->accessKeySecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRoleArn()
|
||||
{
|
||||
return $this->roleArn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRoleSessionName()
|
||||
{
|
||||
return $this->roleSessionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPolicy()
|
||||
{
|
||||
return $this->policy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return "$this->accessKeyId#$this->accessKeySecret#$this->roleArn#$this->roleSessionName";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials\Requests;
|
||||
|
||||
use AlibabaCloud\Client\Request\RpcRequest;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Credentials\Providers\Provider;
|
||||
use AlibabaCloud\Client\Credentials\RamRoleArnCredential;
|
||||
|
||||
/**
|
||||
* Retrieving assume role credentials.
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials\Requests
|
||||
*/
|
||||
class AssumeRole extends RpcRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* AssumeRole constructor.
|
||||
*
|
||||
* @param RamRoleArnCredential $arnCredential
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct(RamRoleArnCredential $arnCredential)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->product('Sts');
|
||||
$this->version('2015-04-01');
|
||||
$this->action('AssumeRole');
|
||||
$this->host('sts.aliyuncs.com');
|
||||
$this->scheme('https');
|
||||
$this->regionId('cn-hangzhou');
|
||||
$this->options['verify'] = false;
|
||||
$this->options['query']['RoleArn'] = $arnCredential->getRoleArn();
|
||||
$this->options['query']['RoleSessionName'] = $arnCredential->getRoleSessionName();
|
||||
$this->options['query']['DurationSeconds'] = Provider::DURATION_SECONDS;
|
||||
if ($arnCredential->getPolicy()) {
|
||||
if (is_array($arnCredential->getPolicy())) {
|
||||
$this->options['query']['Policy'] = json_encode($arnCredential->getPolicy());
|
||||
}
|
||||
if (is_string($arnCredential->getPolicy())) {
|
||||
$this->options['query']['Policy'] = $arnCredential->getPolicy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials\Requests;
|
||||
|
||||
use AlibabaCloud\Client\Request\RpcRequest;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Credentials\Providers\Provider;
|
||||
|
||||
/**
|
||||
* Use the RSA key pair to complete the authentication (supported only on Japanese site)
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials\Requests
|
||||
*/
|
||||
class GenerateSessionAccessKey extends RpcRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* GenerateSessionAccessKey constructor.
|
||||
*
|
||||
* @param string $publicKeyId
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($publicKeyId)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->product('Sts');
|
||||
$this->version('2015-04-01');
|
||||
$this->action('GenerateSessionAccessKey');
|
||||
$this->host('sts.ap-northeast-1.aliyuncs.com');
|
||||
$this->scheme('https');
|
||||
$this->regionId('cn-hangzhou');
|
||||
$this->options['verify'] = false;
|
||||
$this->options['query']['PublicKeyId'] = $publicKeyId;
|
||||
$this->options['query']['DurationSeconds'] = Provider::DURATION_SECONDS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials;
|
||||
|
||||
use Exception;
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\Filter\CredentialFilter;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Use the RSA key pair to complete the authentication (supported only on Japanese site)
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials
|
||||
*/
|
||||
class RsaKeyPairCredential implements CredentialsInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $publicKeyId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $privateKey;
|
||||
|
||||
/**
|
||||
* RsaKeyPairCredential constructor.
|
||||
*
|
||||
* @param string $publicKeyId
|
||||
* @param string $privateKeyFile
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($publicKeyId, $privateKeyFile)
|
||||
{
|
||||
CredentialFilter::publicKeyId($publicKeyId);
|
||||
CredentialFilter::privateKeyFile($privateKeyFile);
|
||||
|
||||
$this->publicKeyId = $publicKeyId;
|
||||
try {
|
||||
$this->privateKey = file_get_contents($privateKeyFile);
|
||||
} catch (Exception $exception) {
|
||||
throw new ClientException(
|
||||
$exception->getMessage(),
|
||||
SDK::INVALID_CREDENTIAL
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPrivateKey()
|
||||
{
|
||||
return $this->privateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPublicKeyId()
|
||||
{
|
||||
return $this->publicKeyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return "publicKeyId#$this->publicKeyId";
|
||||
}
|
||||
}
|
||||
80
app/Common/extend/alibabacloud/client/src/Credentials/StsCredential.php
Executable file
80
app/Common/extend/alibabacloud/client/src/Credentials/StsCredential.php
Executable file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Credentials;
|
||||
|
||||
use AlibabaCloud\Client\Filter\CredentialFilter;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Use the STS Token to complete the authentication.
|
||||
*
|
||||
* @package AlibabaCloud\Client\Credentials
|
||||
*/
|
||||
class StsCredential implements CredentialsInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $accessKeyId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $accessKeySecret;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $securityToken;
|
||||
|
||||
/**
|
||||
* StsCredential constructor.
|
||||
*
|
||||
* @param string $accessKeyId Access key ID
|
||||
* @param string $accessKeySecret Access Key Secret
|
||||
* @param string $securityToken Security Token
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct($accessKeyId, $accessKeySecret, $securityToken = '')
|
||||
{
|
||||
CredentialFilter::AccessKey($accessKeyId, $accessKeySecret);
|
||||
|
||||
$this->accessKeyId = $accessKeyId;
|
||||
$this->accessKeySecret = $accessKeySecret;
|
||||
$this->securityToken = $securityToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessKeyId()
|
||||
{
|
||||
return $this->accessKeyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessKeySecret()
|
||||
{
|
||||
return $this->accessKeySecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSecurityToken()
|
||||
{
|
||||
return $this->securityToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return "$this->accessKeyId#$this->accessKeySecret#$this->securityToken";
|
||||
}
|
||||
}
|
||||
55
app/Common/extend/alibabacloud/client/src/DefaultAcsClient.php
Executable file
55
app/Common/extend/alibabacloud/client/src/DefaultAcsClient.php
Executable file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client;
|
||||
|
||||
use AlibabaCloud\Client\Result\Result;
|
||||
use AlibabaCloud\Client\Clients\Client;
|
||||
use AlibabaCloud\Client\Request\Request;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
|
||||
/**
|
||||
* Class DefaultAcsClient
|
||||
*
|
||||
* @package AlibabaCloud
|
||||
*
|
||||
* @deprecated deprecated since version 2.0, Use AlibabaCloud instead.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class DefaultAcsClient
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $randClientName;
|
||||
|
||||
/**
|
||||
* DefaultAcsClient constructor.
|
||||
*
|
||||
* @param Client $client
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct(Client $client)
|
||||
{
|
||||
$this->randClientName = \uniqid('', true);
|
||||
$client->name($this->randClientName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request|Result $request
|
||||
*
|
||||
* @return Result|string
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
public function getAcsResponse($request)
|
||||
{
|
||||
if ($request instanceof Result) {
|
||||
return $request;
|
||||
}
|
||||
|
||||
return $request->client($this->randClientName)->request();
|
||||
}
|
||||
}
|
||||
64
app/Common/extend/alibabacloud/client/src/Encode.php
Executable file
64
app/Common/extend/alibabacloud/client/src/Encode.php
Executable file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client;
|
||||
|
||||
/**
|
||||
* Class Encode
|
||||
*
|
||||
* @package AlibabaCloud\Client
|
||||
*/
|
||||
class Encode
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function create(array $data)
|
||||
{
|
||||
return new static($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
private function __construct(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
$string = '';
|
||||
foreach ($this->data as $key => $value) {
|
||||
$encode = rawurlencode($value);
|
||||
$string .= "$key=$encode&";
|
||||
}
|
||||
|
||||
if (0 < count($this->data)) {
|
||||
$string = substr($string, 0, -1);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function ksort()
|
||||
{
|
||||
ksort($this->data);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Exception;
|
||||
|
||||
use Exception;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class AlibabaCloudException
|
||||
*
|
||||
* @package AlibabaCloud\Client\Exception
|
||||
*/
|
||||
abstract class AlibabaCloudException extends Exception
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $errorCode;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $errorMessage;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorCode()
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
public function setErrorCode()
|
||||
{
|
||||
throw new RuntimeException('deprecated since 2.0.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorMessage()
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param $errorMessage
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function setErrorMessage($errorMessage)
|
||||
{
|
||||
$this->errorMessage = $errorMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
public function setErrorType()
|
||||
{
|
||||
}
|
||||
}
|
||||
38
app/Common/extend/alibabacloud/client/src/Exception/ClientException.php
Executable file
38
app/Common/extend/alibabacloud/client/src/Exception/ClientException.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Exception;
|
||||
|
||||
use Exception;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class ClientException
|
||||
*
|
||||
* @package AlibabaCloud\Client\Exception
|
||||
*/
|
||||
class ClientException extends AlibabaCloudException
|
||||
{
|
||||
|
||||
/**
|
||||
* ClientException constructor.
|
||||
*
|
||||
* @param string $errorMessage
|
||||
* @param string $errorCode
|
||||
* @param Exception|null $previous
|
||||
*/
|
||||
public function __construct($errorMessage, $errorCode, $previous = null)
|
||||
{
|
||||
parent::__construct($errorMessage, 0, $previous);
|
||||
$this->errorMessage = $errorMessage;
|
||||
$this->errorCode = $errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
public function getErrorType()
|
||||
{
|
||||
return 'Client';
|
||||
}
|
||||
}
|
||||
158
app/Common/extend/alibabacloud/client/src/Exception/ServerException.php
Executable file
158
app/Common/extend/alibabacloud/client/src/Exception/ServerException.php
Executable file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Exception;
|
||||
|
||||
use Stringy\Stringy;
|
||||
use RuntimeException;
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\Result\Result;
|
||||
|
||||
/**
|
||||
* Class ServerException
|
||||
*
|
||||
* @package AlibabaCloud\Client\Exception
|
||||
*/
|
||||
class ServerException extends AlibabaCloudException
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $requestId;
|
||||
|
||||
/**
|
||||
* @var Result
|
||||
*/
|
||||
protected $result;
|
||||
|
||||
/**
|
||||
* ServerException constructor.
|
||||
*
|
||||
* @param Result|null $result
|
||||
* @param string $errorMessage
|
||||
* @param string $errorCode
|
||||
*/
|
||||
public function __construct(
|
||||
Result $result,
|
||||
$errorMessage = SDK::RESPONSE_EMPTY,
|
||||
$errorCode = SDK::SERVICE_UNKNOWN_ERROR
|
||||
) {
|
||||
$this->result = $result;
|
||||
$this->errorMessage = $errorMessage;
|
||||
$this->errorCode = $errorCode;
|
||||
$this->resolvePropertiesByReturn();
|
||||
$this->distinguishSignatureErrors();
|
||||
$this->bodyAsErrorMessage();
|
||||
|
||||
parent::__construct(
|
||||
$this->getMessageString(),
|
||||
$this->result->getStatusCode()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the error message based on the return of the server.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function resolvePropertiesByReturn()
|
||||
{
|
||||
if (isset($this->result['message'])) {
|
||||
$this->errorMessage = $this->result['message'];
|
||||
$this->errorCode = $this->result['code'];
|
||||
}
|
||||
if (isset($this->result['Message'])) {
|
||||
$this->errorMessage = $this->result['Message'];
|
||||
$this->errorCode = $this->result['Code'];
|
||||
}
|
||||
if (isset($this->result['errorMsg'])) {
|
||||
$this->errorMessage = $this->result['errorMsg'];
|
||||
$this->errorCode = $this->result['errorCode'];
|
||||
}
|
||||
if (isset($this->result['requestId'])) {
|
||||
$this->requestId = $this->result['requestId'];
|
||||
}
|
||||
if (isset($this->result['RequestId'])) {
|
||||
$this->requestId = $this->result['RequestId'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the string to be signed are the same with server's, it is considered a credential error.
|
||||
*/
|
||||
private function distinguishSignatureErrors()
|
||||
{
|
||||
if ($this->result->getRequest()
|
||||
&& Stringy::create($this->errorMessage)->contains($this->result->getRequest()->stringToSign())) {
|
||||
$this->errorCode = 'InvalidAccessKeySecret';
|
||||
$this->errorMessage = 'Specified Access Key Secret is not valid.';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the error message matches the default message and
|
||||
* the server has returned content, use the return content
|
||||
*/
|
||||
private function bodyAsErrorMessage()
|
||||
{
|
||||
$body = (string)$this->result->getBody();
|
||||
if ($this->errorMessage === SDK::RESPONSE_EMPTY && $body) {
|
||||
$this->errorMessage = $body;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get standard exception message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getMessageString()
|
||||
{
|
||||
$message = "$this->errorCode: $this->errorMessage RequestId: $this->requestId";
|
||||
|
||||
if ($this->getResult()->getRequest()) {
|
||||
$method = $this->getResult()->getRequest()->method;
|
||||
$uri = (string)$this->getResult()->getRequest()->uri;
|
||||
$message .= " $method \"$uri\"";
|
||||
if ($this->result) {
|
||||
$message .= ' ' . $this->result->getStatusCode();
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Result
|
||||
*/
|
||||
public function getResult()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestId()
|
||||
{
|
||||
return $this->requestId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
public function getErrorType()
|
||||
{
|
||||
return 'Server';
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
*/
|
||||
public function getHttpStatus()
|
||||
{
|
||||
return $this->getResult()->getStatusCode();
|
||||
}
|
||||
}
|
||||
245
app/Common/extend/alibabacloud/client/src/Filter/ApiFilter.php
Executable file
245
app/Common/extend/alibabacloud/client/src/Filter/ApiFilter.php
Executable file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Filter;
|
||||
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class ApiFilter
|
||||
*
|
||||
* @package AlibabaCloud\Client\Filter
|
||||
*/
|
||||
class ApiFilter
|
||||
{
|
||||
/**
|
||||
* @param $serviceCode
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function serviceCode($serviceCode)
|
||||
{
|
||||
if (!is_string($serviceCode)) {
|
||||
throw new ClientException(
|
||||
'Service Code must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($serviceCode === '') {
|
||||
throw new ClientException(
|
||||
'Service Code cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $serviceCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $endpointType
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function endpointType($endpointType)
|
||||
{
|
||||
if (!is_string($endpointType)) {
|
||||
throw new ClientException(
|
||||
'Endpoint Type must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($endpointType === '') {
|
||||
throw new ClientException(
|
||||
'Endpoint Type cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $endpointType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $action
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function action($action)
|
||||
{
|
||||
if (!is_string($action)) {
|
||||
throw new ClientException(
|
||||
'Action must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($action === '') {
|
||||
throw new ClientException(
|
||||
'Action cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $endpointSuffix
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function endpointSuffix($endpointSuffix)
|
||||
{
|
||||
if (!is_string($endpointSuffix)) {
|
||||
throw new ClientException(
|
||||
'Endpoint Suffix must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($endpointSuffix === '') {
|
||||
throw new ClientException(
|
||||
'Endpoint Suffix cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $endpointSuffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $network
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function network($network)
|
||||
{
|
||||
if (!is_string($network)) {
|
||||
throw new ClientException(
|
||||
'Network Suffix must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($network === '') {
|
||||
throw new ClientException(
|
||||
'Network Suffix cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $network;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $version
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function version($version)
|
||||
{
|
||||
if (!is_string($version)) {
|
||||
throw new ClientException(
|
||||
'Version must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($version === '') {
|
||||
throw new ClientException(
|
||||
'Version cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $format
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function format($format)
|
||||
{
|
||||
if (!is_string($format)) {
|
||||
throw new ClientException(
|
||||
'Format must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($format === '') {
|
||||
throw new ClientException(
|
||||
'Format cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return \strtoupper($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $product
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function product($product)
|
||||
{
|
||||
if (!is_string($product)) {
|
||||
throw new ClientException(
|
||||
'Product must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($product === '') {
|
||||
throw new ClientException(
|
||||
'Product cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pattern
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function pattern($pattern)
|
||||
{
|
||||
if (!is_string($pattern)) {
|
||||
throw new ClientException(
|
||||
'Pattern must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($pattern === '') {
|
||||
throw new ClientException(
|
||||
'Pattern cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $pattern;
|
||||
}
|
||||
}
|
||||
139
app/Common/extend/alibabacloud/client/src/Filter/ClientFilter.php
Executable file
139
app/Common/extend/alibabacloud/client/src/Filter/ClientFilter.php
Executable file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Filter;
|
||||
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class ClientFilter
|
||||
*
|
||||
* @package AlibabaCloud\Client\Filter
|
||||
*/
|
||||
class ClientFilter
|
||||
{
|
||||
/**
|
||||
* @param $regionId
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function regionId($regionId)
|
||||
{
|
||||
if (!is_string($regionId)) {
|
||||
throw new ClientException(
|
||||
'Region ID must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($regionId === '') {
|
||||
throw new ClientException(
|
||||
'Region ID cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return strtolower($regionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $clientName
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function clientName($clientName)
|
||||
{
|
||||
if (!is_string($clientName)) {
|
||||
throw new ClientException(
|
||||
'Client Name must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($clientName === '') {
|
||||
throw new ClientException(
|
||||
'Client Name cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return strtolower($clientName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $times
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function retry($times)
|
||||
{
|
||||
if (!is_int($times)) {
|
||||
throw new ClientException(
|
||||
'Retry must be a int',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $times;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $connectTimeout
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function connectTimeout($connectTimeout)
|
||||
{
|
||||
if ($connectTimeout === '') {
|
||||
throw new ClientException(
|
||||
'Connect Timeout cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $connectTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $timeout
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function timeout($timeout)
|
||||
{
|
||||
if ($timeout === '') {
|
||||
throw new ClientException(
|
||||
'Timeout cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $Milliseconds
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function milliseconds($Milliseconds)
|
||||
{
|
||||
if (!is_int($Milliseconds)) {
|
||||
throw new ClientException(
|
||||
'Milliseconds must be int',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $Milliseconds;
|
||||
}
|
||||
}
|
||||
152
app/Common/extend/alibabacloud/client/src/Filter/CredentialFilter.php
Executable file
152
app/Common/extend/alibabacloud/client/src/Filter/CredentialFilter.php
Executable file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Filter;
|
||||
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class CredentialFilter
|
||||
*
|
||||
* @package AlibabaCloud\Client\Filter
|
||||
*/
|
||||
class CredentialFilter
|
||||
{
|
||||
/**
|
||||
* @param $bearerToken
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function bearerToken($bearerToken)
|
||||
{
|
||||
if (!is_string($bearerToken)) {
|
||||
throw new ClientException(
|
||||
'Bearer Token must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($bearerToken === '') {
|
||||
throw new ClientException(
|
||||
'Bearer Token cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $bearerToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $publicKeyId
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function publicKeyId($publicKeyId)
|
||||
{
|
||||
if (!is_string($publicKeyId)) {
|
||||
throw new ClientException(
|
||||
'Public Key ID must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($publicKeyId === '') {
|
||||
throw new ClientException(
|
||||
'Public Key ID cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $publicKeyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $privateKeyFile
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function privateKeyFile($privateKeyFile)
|
||||
{
|
||||
if (!is_string($privateKeyFile)) {
|
||||
throw new ClientException(
|
||||
'Private Key File must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($privateKeyFile === '') {
|
||||
throw new ClientException(
|
||||
'Private Key File cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $privateKeyFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $roleName
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function roleName($roleName)
|
||||
{
|
||||
if (!is_string($roleName)) {
|
||||
throw new ClientException(
|
||||
'Role Name must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($roleName === '') {
|
||||
throw new ClientException(
|
||||
'Role Name cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $roleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessKeyId
|
||||
* @param string $accessKeySecret
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function AccessKey($accessKeyId, $accessKeySecret)
|
||||
{
|
||||
if (!is_string($accessKeyId)) {
|
||||
throw new ClientException(
|
||||
'AccessKey ID must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($accessKeyId === '') {
|
||||
throw new ClientException(
|
||||
'AccessKey ID cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if (!is_string($accessKeySecret)) {
|
||||
throw new ClientException(
|
||||
'AccessKey Secret must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($accessKeySecret === '') {
|
||||
throw new ClientException(
|
||||
'AccessKey Secret cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
67
app/Common/extend/alibabacloud/client/src/Filter/Filter.php
Executable file
67
app/Common/extend/alibabacloud/client/src/Filter/Filter.php
Executable file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Filter;
|
||||
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class Filter
|
||||
*
|
||||
* @package AlibabaCloud\Client\Filter
|
||||
*/
|
||||
class Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function name($name)
|
||||
{
|
||||
if (!is_string($name)) {
|
||||
throw new ClientException(
|
||||
'Name must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($name === '') {
|
||||
throw new ClientException(
|
||||
'Name cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function value($value)
|
||||
{
|
||||
if (!is_numeric($value) && !is_string($value)) {
|
||||
throw new ClientException(
|
||||
'Value must be a string or int',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($value === '') {
|
||||
throw new ClientException(
|
||||
'Value cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
166
app/Common/extend/alibabacloud/client/src/Filter/HttpFilter.php
Executable file
166
app/Common/extend/alibabacloud/client/src/Filter/HttpFilter.php
Executable file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Filter;
|
||||
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class HttpFilter
|
||||
*
|
||||
* @package AlibabaCloud\Client\Filter
|
||||
*/
|
||||
class HttpFilter
|
||||
{
|
||||
/**
|
||||
* @param $host
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function host($host)
|
||||
{
|
||||
if (!is_string($host)) {
|
||||
throw new ClientException(
|
||||
'Host must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($host === '') {
|
||||
throw new ClientException(
|
||||
'Host cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $host;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $scheme
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function scheme($scheme)
|
||||
{
|
||||
if (!is_string($scheme)) {
|
||||
throw new ClientException(
|
||||
'Scheme must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($scheme === '') {
|
||||
throw new ClientException(
|
||||
'Scheme cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $body
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function body($body)
|
||||
{
|
||||
if (!is_string($body) && !is_numeric($body)) {
|
||||
throw new ClientException(
|
||||
'Body must be a string or int',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($body === '') {
|
||||
throw new ClientException(
|
||||
'Body cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $method
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function method($method)
|
||||
{
|
||||
if (!is_string($method)) {
|
||||
throw new ClientException(
|
||||
'Method must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($method === '') {
|
||||
throw new ClientException(
|
||||
'Method cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return \strtoupper($method);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $contentType
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function contentType($contentType)
|
||||
{
|
||||
if (!is_string($contentType)) {
|
||||
throw new ClientException(
|
||||
'Content-Type must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($contentType === '') {
|
||||
throw new ClientException(
|
||||
'Content-Type cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $accept
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function accept($accept)
|
||||
{
|
||||
if (!is_string($accept)) {
|
||||
throw new ClientException(
|
||||
'Accept must be a string',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
if ($accept === '') {
|
||||
throw new ClientException(
|
||||
'Accept cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $accept;
|
||||
}
|
||||
}
|
||||
289
app/Common/extend/alibabacloud/client/src/Functions.php
Executable file
289
app/Common/extend/alibabacloud/client/src/Functions.php
Executable file
@@ -0,0 +1,289 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client;
|
||||
|
||||
use Closure;
|
||||
use Stringy\Stringy;
|
||||
use League\CLImate\CLImate;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global Functions for Alibaba Cloud
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Some common global functions are defined here.
|
||||
| This file will be automatically loaded.
|
||||
|
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param $filename
|
||||
* @param bool $throwException
|
||||
*
|
||||
* @return bool
|
||||
* @throws ClientException
|
||||
*/
|
||||
function inOpenBasedir($filename, $throwException = false)
|
||||
{
|
||||
$open_basedir = ini_get('open_basedir');
|
||||
if (!$open_basedir) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$dirs = explode(PATH_SEPARATOR, $open_basedir);
|
||||
if (empty($dirs)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (inDir($filename, $dirs)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($throwException === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new ClientException(
|
||||
'open_basedir restriction in effect. '
|
||||
. "File($filename) is not within the allowed path(s): ($open_basedir)",
|
||||
'SDK.InvalidPath'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @param array $dirs
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function inDir($filename, array $dirs)
|
||||
{
|
||||
foreach ($dirs as $dir) {
|
||||
if (!Stringy::create($dir)->endsWith(DIRECTORY_SEPARATOR)) {
|
||||
$dir .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
if (0 === strpos($filename, $dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
function isWindows()
|
||||
{
|
||||
return PATH_SEPARATOR === ';';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CLImate
|
||||
*/
|
||||
function cliMate()
|
||||
{
|
||||
return new CLImate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string|null $flank
|
||||
* @param string|null $char
|
||||
* @param int|null $length
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function backgroundRed($string, $flank = null, $char = null, $length = null)
|
||||
{
|
||||
cliMate()->br();
|
||||
if ($flank !== null) {
|
||||
cliMate()->backgroundRed()->flank($flank, $char, $length);
|
||||
cliMate()->br();
|
||||
}
|
||||
cliMate()->backgroundRed($string);
|
||||
cliMate()->br();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string|null $flank
|
||||
* @param string|null $char
|
||||
* @param int|null $length
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function backgroundGreen($string, $flank = null, $char = null, $length = null)
|
||||
{
|
||||
cliMate()->br();
|
||||
if ($flank !== null) {
|
||||
cliMate()->backgroundGreen()->flank($flank, $char, $length);
|
||||
}
|
||||
cliMate()->backgroundGreen($string);
|
||||
cliMate()->br();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string|null $flank
|
||||
* @param string|null $char
|
||||
* @param int|null $length
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function backgroundBlue($string, $flank = null, $char = null, $length = null)
|
||||
{
|
||||
cliMate()->br();
|
||||
if ($flank !== null) {
|
||||
cliMate()->backgroundBlue()->flank($flank, $char, $length);
|
||||
}
|
||||
cliMate()->backgroundBlue($string);
|
||||
cliMate()->br();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string|null $flank
|
||||
* @param string|null $char
|
||||
* @param int|null $length
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function backgroundMagenta($string, $flank = null, $char = null, $length = null)
|
||||
{
|
||||
cliMate()->br();
|
||||
if ($flank !== null) {
|
||||
cliMate()->backgroundMagenta()->flank($flank, $char, $length);
|
||||
}
|
||||
cliMate()->backgroundMagenta($string);
|
||||
cliMate()->br();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*/
|
||||
function json(array $array)
|
||||
{
|
||||
cliMate()->br();
|
||||
cliMate()->backgroundGreen()->json($array);
|
||||
cliMate()->br();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function redTable($array)
|
||||
{
|
||||
/**
|
||||
* @noinspection PhpUndefinedMethodInspection
|
||||
*/
|
||||
cliMate()->redTable($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $result
|
||||
* @param string $title
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function block($result, $title)
|
||||
{
|
||||
cliMate()->backgroundGreen()->flank($title, '--', 20);
|
||||
dump($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of an environment variable.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function env($key, $default = null)
|
||||
{
|
||||
$value = getenv($key);
|
||||
|
||||
if ($value === false) {
|
||||
return value($default);
|
||||
}
|
||||
|
||||
if (envSubstr($value)) {
|
||||
return substr($value, 1, -1);
|
||||
}
|
||||
|
||||
return envConversion($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return bool|string|null
|
||||
*/
|
||||
function envConversion($value)
|
||||
{
|
||||
$key = strtolower($value);
|
||||
|
||||
if ($key === 'null' || $key === '(null)') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$list = [
|
||||
'true' => true,
|
||||
'(true)' => true,
|
||||
'false' => false,
|
||||
'(false)' => false,
|
||||
'empty' => '',
|
||||
'(empty)' => '',
|
||||
];
|
||||
|
||||
return isset($list[$key]) ? $list[$key] : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
*
|
||||
* @return bool|mixed
|
||||
* @throws ClientException
|
||||
*/
|
||||
function envNotEmpty($key)
|
||||
{
|
||||
$value = env($key, false);
|
||||
if ($value !== false && !$value) {
|
||||
throw new ClientException(
|
||||
"Environment variable '$key' cannot be empty",
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
if ($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function envSubstr($value)
|
||||
{
|
||||
return ($valueLength = strlen($value)) > 1 && strpos($value, '"') === 0 && $value[$valueLength - 1] === '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default value of the given value.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function value($value)
|
||||
{
|
||||
return $value instanceof Closure ? $value() : $value;
|
||||
}
|
||||
78
app/Common/extend/alibabacloud/client/src/Log/LogFormatter.php
Executable file
78
app/Common/extend/alibabacloud/client/src/Log/LogFormatter.php
Executable file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Log;
|
||||
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use DateTimeZone;
|
||||
use GuzzleHttp\MessageFormatter;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Class LogFormatter
|
||||
*
|
||||
* @package AlibabaCloud\Client\Log
|
||||
*/
|
||||
class LogFormatter extends MessageFormatter
|
||||
{
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
private static $logStartTime = 0;
|
||||
|
||||
/**
|
||||
* @var DateTime
|
||||
*/
|
||||
private static $ts;
|
||||
|
||||
/** @var string Template used to format log messages */
|
||||
public $template;
|
||||
|
||||
/**
|
||||
* @param string $template Log message template
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($template)
|
||||
{
|
||||
parent::__construct($template);
|
||||
self::$logStartTime = microtime(true);
|
||||
$this->template = $template;
|
||||
$timezone = new DateTimeZone(date_default_timezone_get() ?: 'UTC');
|
||||
if (PHP_VERSION_ID < 70100) {
|
||||
self::$ts = DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), $timezone);
|
||||
} else {
|
||||
self::$ts = new DateTime(null, $timezone);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted message string.
|
||||
*
|
||||
* @param RequestInterface $request Request that was sent
|
||||
* @param ResponseInterface $response Response that was received
|
||||
* @param Exception $error Exception that was received
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format(
|
||||
RequestInterface $request,
|
||||
ResponseInterface $response = null,
|
||||
Exception $error = null
|
||||
) {
|
||||
$this->template = str_replace('{pid}', getmypid(), $this->template);
|
||||
$this->template = str_replace('{cost}', self::getCost(), $this->template);
|
||||
$this->template = str_replace('{start_time}', self::$ts->format('Y-m-d H:i:s.u'), $this->template);
|
||||
|
||||
return (new MessageFormatter($this->template))->format($request, $response, $error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float|mixed
|
||||
*/
|
||||
private static function getCost()
|
||||
{
|
||||
return microtime(true) - self::$logStartTime;
|
||||
}
|
||||
}
|
||||
74
app/Common/extend/alibabacloud/client/src/Profile/DefaultProfile.php
Executable file
74
app/Common/extend/alibabacloud/client/src/Profile/DefaultProfile.php
Executable file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Profile;
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Clients\Client;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class DefaultProfile
|
||||
*
|
||||
* @package AlibabaCloud\Client\Profile
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated deprecated since version 2.0, Use AlibabaCloud instead.
|
||||
*/
|
||||
class DefaultProfile
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $regionId
|
||||
* @param string $accessKeyId
|
||||
* @param string $accessKeySecret
|
||||
*
|
||||
* @return Client
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function getProfile($regionId, $accessKeyId, $accessKeySecret)
|
||||
{
|
||||
return AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret)
|
||||
->regionId($regionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $regionId
|
||||
* @param string $accessKeyId
|
||||
* @param string $accessKeySecret
|
||||
* @param string $roleArn
|
||||
* @param string $roleSessionName
|
||||
*
|
||||
* @return Client
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function getRamRoleArnProfile($regionId, $accessKeyId, $accessKeySecret, $roleArn, $roleSessionName)
|
||||
{
|
||||
return AlibabaCloud::ramRoleArnClient($accessKeyId, $accessKeySecret, $roleArn, $roleSessionName)
|
||||
->regionId($regionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $regionId
|
||||
* @param string $roleName
|
||||
*
|
||||
* @return Client
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function getEcsRamRoleProfile($regionId, $roleName)
|
||||
{
|
||||
return AlibabaCloud::ecsRamRoleClient($roleName)
|
||||
->regionId($regionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $regionId
|
||||
* @param string $bearerToken
|
||||
*
|
||||
* @return Client
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function getBearerTokenProfile($regionId, $bearerToken)
|
||||
{
|
||||
return AlibabaCloud::bearerTokenClient($bearerToken)
|
||||
->regionId($regionId);
|
||||
}
|
||||
}
|
||||
18
app/Common/extend/alibabacloud/client/src/Regions/EndpointProvider.php
Executable file
18
app/Common/extend/alibabacloud/client/src/Regions/EndpointProvider.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Regions;
|
||||
|
||||
use AlibabaCloud\Client\Traits\EndpointTrait;
|
||||
|
||||
/**
|
||||
* Class EndpointProvider
|
||||
*
|
||||
* @package AlibabaCloud\Client\Regions
|
||||
*
|
||||
* @deprecated deprecated since version 2.0, Use AlibabaCloud instead.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class EndpointProvider
|
||||
{
|
||||
use EndpointTrait;
|
||||
}
|
||||
160
app/Common/extend/alibabacloud/client/src/Regions/LocationService.php
Executable file
160
app/Common/extend/alibabacloud/client/src/Regions/LocationService.php
Executable file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Regions;
|
||||
|
||||
use Exception;
|
||||
use RuntimeException;
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\Config\Config;
|
||||
use AlibabaCloud\Client\Request\Request;
|
||||
use AlibabaCloud\Client\Filter\ApiFilter;
|
||||
use AlibabaCloud\Client\Filter\HttpFilter;
|
||||
use AlibabaCloud\Client\Filter\ClientFilter;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
|
||||
/**
|
||||
* Class LocationService
|
||||
*
|
||||
* @package AlibabaCloud\Client\Regions
|
||||
*/
|
||||
class LocationService
|
||||
{
|
||||
/**
|
||||
* Global Region Name
|
||||
*/
|
||||
const GLOBAL_REGION = 'global';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $hosts = [];
|
||||
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* LocationService constructor.
|
||||
*
|
||||
* @param Request $request
|
||||
*/
|
||||
private function __construct(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $domain
|
||||
*
|
||||
* @return string
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function findProductDomain(Request $request, $domain = 'location.aliyuncs.com')
|
||||
{
|
||||
return self::resolveHost($request, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $regionId
|
||||
* @param $product
|
||||
* @param $domain
|
||||
*
|
||||
* @throws ClientException
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function addEndPoint($regionId, $product, $domain)
|
||||
{
|
||||
self::addHost($product, $domain, $regionId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $domain
|
||||
*
|
||||
* @return string
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
public static function resolveHost(Request $request, $domain = 'location.aliyuncs.com')
|
||||
{
|
||||
$locationService = new static($request);
|
||||
$product = $locationService->request->product;
|
||||
$regionId = $locationService->request->realRegionId();
|
||||
|
||||
if (!isset(self::$hosts[$product][$regionId])) {
|
||||
self::$hosts[$product][$regionId] = self::getResult($locationService, $domain);
|
||||
}
|
||||
|
||||
return self::$hosts[$product][$regionId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param static $locationService
|
||||
* @param string $domain
|
||||
*
|
||||
* @return string
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
private static function getResult($locationService, $domain)
|
||||
{
|
||||
$locationRequest = new LocationServiceRequest($locationService->request, $domain);
|
||||
|
||||
$result = $locationRequest->request();
|
||||
|
||||
if (!isset($result['Endpoints']['Endpoint'][0]['Endpoint'])) {
|
||||
throw new ClientException(
|
||||
'Not found Region ID in ' . $domain,
|
||||
SDK::INVALID_REGION_ID
|
||||
);
|
||||
}
|
||||
|
||||
return $result['Endpoints']['Endpoint'][0]['Endpoint'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $product
|
||||
* @param string $host
|
||||
* @param string $regionId
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public static function addHost($product, $host, $regionId = self::GLOBAL_REGION)
|
||||
{
|
||||
ApiFilter::product($product);
|
||||
|
||||
HttpFilter::host($host);
|
||||
|
||||
ClientFilter::regionId($regionId);
|
||||
|
||||
self::$hosts[$product][$regionId] = $host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update endpoints from OSS.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function updateEndpoints()
|
||||
{
|
||||
$ossUrl = 'https://openapi-endpoints.oss-cn-hangzhou.aliyuncs.com/endpoints.json';
|
||||
$json = \file_get_contents($ossUrl);
|
||||
$list = \json_decode($json, true);
|
||||
|
||||
foreach ($list['endpoints'] as $endpoint) {
|
||||
Config::set(
|
||||
"endpoints.{$endpoint['service']}.{$endpoint['regionid']}",
|
||||
\strtolower($endpoint['endpoint'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
46
app/Common/extend/alibabacloud/client/src/Regions/LocationServiceRequest.php
Executable file
46
app/Common/extend/alibabacloud/client/src/Regions/LocationServiceRequest.php
Executable file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Regions;
|
||||
|
||||
use AlibabaCloud\Client\Request\Request;
|
||||
use AlibabaCloud\Client\Request\RpcRequest;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
|
||||
/**
|
||||
* Class LocationServiceRequest
|
||||
*
|
||||
* @package AlibabaCloud\Client\Regions
|
||||
*/
|
||||
class LocationServiceRequest extends RpcRequest
|
||||
{
|
||||
|
||||
/**
|
||||
* LocationServiceRequest constructor.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $domain
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct(Request $request, $domain)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->product('Location');
|
||||
$this->version('2015-06-12');
|
||||
$this->action('DescribeEndpoints');
|
||||
$this->regionId('cn-hangzhou');
|
||||
$this->format('JSON');
|
||||
$this->options['query']['Id'] = $request->realRegionId();
|
||||
$this->options['query']['ServiceCode'] = $request->serviceCode;
|
||||
$this->options['query']['Type'] = $request->endpointType;
|
||||
$this->client($request->client);
|
||||
$this->host($domain);
|
||||
if (isset($request->options['timeout'])) {
|
||||
$this->timeout($request->options['timeout']);
|
||||
}
|
||||
|
||||
if (isset($request->options['connect_timeout'])) {
|
||||
$this->connectTimeout($request->options['connect_timeout']);
|
||||
}
|
||||
}
|
||||
}
|
||||
112
app/Common/extend/alibabacloud/client/src/Release.php
Executable file
112
app/Common/extend/alibabacloud/client/src/Release.php
Executable file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client;
|
||||
|
||||
use Composer\Script\Event;
|
||||
|
||||
/**
|
||||
* Class Release
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @package AlibabaCloud\Client
|
||||
*/
|
||||
class Release
|
||||
{
|
||||
/**
|
||||
* @param Event $event
|
||||
*/
|
||||
public static function release(Event $event)
|
||||
{
|
||||
$arguments = $event->getArguments();
|
||||
if (count($arguments) <= 1) {
|
||||
echo 'Missing ChangeLog';
|
||||
|
||||
return;
|
||||
}
|
||||
self::updateChangelogFile($arguments[0], $arguments[1]);
|
||||
self::changeVersionInCode($arguments[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $version
|
||||
* @param $changeLog
|
||||
*/
|
||||
private static function updateChangelogFile($version, $changeLog)
|
||||
{
|
||||
$content = preg_replace(
|
||||
'/# CHANGELOG/',
|
||||
'# CHANGELOG'
|
||||
. "\n"
|
||||
. "\n"
|
||||
. "## $version - " . date('Y-m-d')
|
||||
. self::log($changeLog),
|
||||
self::getChangeLogContent()
|
||||
);
|
||||
|
||||
file_put_contents(self::getChangeLogFile(), $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $changeLog
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function log($changeLog)
|
||||
{
|
||||
$logs = explode('|', $changeLog);
|
||||
$string = "\n";
|
||||
foreach ($logs as $log) {
|
||||
if ($log) {
|
||||
$string .= "- $log." . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private static function getChangeLogContent()
|
||||
{
|
||||
return file_get_contents(self::getChangeLogFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private static function getChangeLogFile()
|
||||
{
|
||||
return __DIR__ . '/../CHANGELOG.md';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $version
|
||||
*/
|
||||
private static function changeVersionInCode($version)
|
||||
{
|
||||
$content = preg_replace(
|
||||
"/const VERSION = \'(.*)\';/",
|
||||
"const VERSION = '" . $version . "';",
|
||||
self::getCodeContent()
|
||||
);
|
||||
|
||||
file_put_contents(self::getCodeFile(), $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private static function getCodeContent()
|
||||
{
|
||||
return file_get_contents(self::getCodeFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private static function getCodeFile()
|
||||
{
|
||||
return __DIR__ . '/AlibabaCloud.php';
|
||||
}
|
||||
}
|
||||
445
app/Common/extend/alibabacloud/client/src/Request/Request.php
Executable file
445
app/Common/extend/alibabacloud/client/src/Request/Request.php
Executable file
@@ -0,0 +1,445 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Request;
|
||||
|
||||
use Exception;
|
||||
use ArrayAccess;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use GuzzleHttp\Middleware;
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use AlibabaCloud\Client\Encode;
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Filter\Filter;
|
||||
use AlibabaCloud\Client\Result\Result;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use GuzzleHttp\Promise\PromiseInterface;
|
||||
use AlibabaCloud\Client\Filter\ApiFilter;
|
||||
use AlibabaCloud\Client\Log\LogFormatter;
|
||||
use AlibabaCloud\Client\Traits\HttpTrait;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use AlibabaCloud\Client\Filter\HttpFilter;
|
||||
use AlibabaCloud\Client\Traits\RegionTrait;
|
||||
use AlibabaCloud\Client\Filter\ClientFilter;
|
||||
use AlibabaCloud\Client\Request\Traits\AcsTrait;
|
||||
use AlibabaCloud\Client\Traits\ArrayAccessTrait;
|
||||
use AlibabaCloud\Client\Traits\ObjectAccessTrait;
|
||||
use AlibabaCloud\Client\Request\Traits\RetryTrait;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
use AlibabaCloud\Client\Request\Traits\ClientTrait;
|
||||
use AlibabaCloud\Client\Request\Traits\DeprecatedTrait;
|
||||
use AlibabaCloud\Client\Credentials\Providers\CredentialsProvider;
|
||||
|
||||
/**
|
||||
* Class Request
|
||||
*
|
||||
* @package AlibabaCloud\Client\Request
|
||||
*
|
||||
* @method string stringToSign()
|
||||
* @method string resolveParameter()
|
||||
*/
|
||||
abstract class Request implements ArrayAccess
|
||||
{
|
||||
use DeprecatedTrait;
|
||||
use HttpTrait;
|
||||
use RegionTrait;
|
||||
use ClientTrait;
|
||||
use AcsTrait;
|
||||
use ArrayAccessTrait;
|
||||
use ObjectAccessTrait;
|
||||
use RetryTrait;
|
||||
|
||||
/**
|
||||
* Request Connect Timeout
|
||||
*/
|
||||
const CONNECT_TIMEOUT = 5;
|
||||
|
||||
/**
|
||||
* Request Timeout
|
||||
*/
|
||||
const TIMEOUT = 10;
|
||||
|
||||
/**
|
||||
* @var string HTTP Method
|
||||
*/
|
||||
public $method = 'GET';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $format = 'JSON';
|
||||
|
||||
/**
|
||||
* @var string HTTP Scheme
|
||||
*/
|
||||
protected $scheme = 'http';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $client;
|
||||
|
||||
/**
|
||||
* @var Uri
|
||||
*/
|
||||
public $uri;
|
||||
|
||||
/**
|
||||
* @var array The original parameters of the request.
|
||||
*/
|
||||
public $data = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $userAgent = [];
|
||||
|
||||
/**
|
||||
* Request constructor.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$this->client = CredentialsProvider::getDefaultName();
|
||||
$this->uri = new Uri();
|
||||
$this->uri = $this->uri->withScheme($this->scheme);
|
||||
$this->options['http_errors'] = false;
|
||||
$this->options['connect_timeout'] = self::CONNECT_TIMEOUT;
|
||||
$this->options['timeout'] = self::TIMEOUT;
|
||||
|
||||
// Turn on debug mode based on environment variable.
|
||||
if (strtolower(\AlibabaCloud\Client\env('DEBUG')) === 'sdk') {
|
||||
$this->options['debug'] = true;
|
||||
}
|
||||
|
||||
// Rewrite configuration if the user has a configuration.
|
||||
if ($options !== []) {
|
||||
$this->options($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function appendUserAgent($name, $value)
|
||||
{
|
||||
$filter_name = Filter::name($name);
|
||||
|
||||
if (!UserAgent::isGuarded($filter_name)) {
|
||||
$this->userAgent[$filter_name] = Filter::value($value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $userAgent
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withUserAgent(array $userAgent)
|
||||
{
|
||||
$this->userAgent = UserAgent::clean($userAgent);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Accept format.
|
||||
*
|
||||
* @param string $format
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function format($format)
|
||||
{
|
||||
$this->format = ApiFilter::format($format);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $contentType
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function contentType($contentType)
|
||||
{
|
||||
$this->options['headers']['Content-Type'] = HttpFilter::contentType($contentType);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accept
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function accept($accept)
|
||||
{
|
||||
$this->options['headers']['Accept'] = HttpFilter::accept($accept);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request body.
|
||||
*
|
||||
* @param string $body
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function body($body)
|
||||
{
|
||||
$this->options['body'] = HttpFilter::body($body);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the json as body.
|
||||
*
|
||||
* @param array|object $content
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function jsonBody($content)
|
||||
{
|
||||
if (!\is_array($content) && !\is_object($content)) {
|
||||
throw new ClientException(
|
||||
'jsonBody only accepts an array or object',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
return $this->body(\json_encode($content));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request scheme.
|
||||
*
|
||||
* @param string $scheme
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function scheme($scheme)
|
||||
{
|
||||
$this->scheme = HttpFilter::scheme($scheme);
|
||||
$this->uri = $this->uri->withScheme($scheme);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the request host.
|
||||
*
|
||||
* @param string $host
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function host($host)
|
||||
{
|
||||
$this->uri = $this->uri->withHost(HttpFilter::host($host));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function method($method)
|
||||
{
|
||||
$this->method = HttpFilter::method($method);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $clientName
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function client($clientName)
|
||||
{
|
||||
$this->client = ClientFilter::clientName($clientName);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function isDebug()
|
||||
{
|
||||
if (isset($this->options['debug'])) {
|
||||
return $this->options['debug'] === true;
|
||||
}
|
||||
|
||||
if (isset($this->httpClient()->options['debug'])) {
|
||||
return $this->httpClient()->options['debug'] === true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
public function resolveOption()
|
||||
{
|
||||
$this->options['headers']['User-Agent'] = UserAgent::toString($this->userAgent);
|
||||
|
||||
$this->cleanQuery();
|
||||
$this->cleanFormParams();
|
||||
$this->resolveHost();
|
||||
$this->resolveParameter();
|
||||
|
||||
if (isset($this->options['form_params'])) {
|
||||
$this->options['form_params'] = \GuzzleHttp\Psr7\parse_query(
|
||||
Encode::create($this->options['form_params'])->toString()
|
||||
);
|
||||
}
|
||||
|
||||
$this->mergeOptionsIntoClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Result
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
public function request()
|
||||
{
|
||||
$this->resolveOption();
|
||||
$result = $this->response();
|
||||
|
||||
if ($this->shouldServerRetry($result)) {
|
||||
return $this->request();
|
||||
}
|
||||
|
||||
if (!$result->isSuccess()) {
|
||||
throw new ServerException($result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/***
|
||||
* @return PromiseInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function requestAsync()
|
||||
{
|
||||
$this->resolveOption();
|
||||
|
||||
return self::createClient($this)->requestAsync(
|
||||
$this->method,
|
||||
(string)$this->uri,
|
||||
$this->options
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function createClient(Request $request = null)
|
||||
{
|
||||
if (AlibabaCloud::hasMock()) {
|
||||
$stack = HandlerStack::create(AlibabaCloud::getMock());
|
||||
} else {
|
||||
$stack = HandlerStack::create();
|
||||
}
|
||||
|
||||
if (AlibabaCloud::isRememberHistory()) {
|
||||
$stack->push(Middleware::history(AlibabaCloud::referenceHistory()));
|
||||
}
|
||||
|
||||
if (AlibabaCloud::getLogger()) {
|
||||
$stack->push(Middleware::log(
|
||||
AlibabaCloud::getLogger(),
|
||||
new LogFormatter(AlibabaCloud::getLogFormat())
|
||||
));
|
||||
}
|
||||
|
||||
$stack->push(Middleware::mapResponse(static function (ResponseInterface $response) use ($request) {
|
||||
return new Result($response, $request);
|
||||
}));
|
||||
|
||||
self::$config['handler'] = $stack;
|
||||
|
||||
return new Client(self::$config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ClientException
|
||||
* @throws Exception
|
||||
*/
|
||||
private function response()
|
||||
{
|
||||
try {
|
||||
return self::createClient($this)->request(
|
||||
$this->method,
|
||||
(string)$this->uri,
|
||||
$this->options
|
||||
);
|
||||
} catch (GuzzleException $exception) {
|
||||
if ($this->shouldClientRetry($exception)) {
|
||||
return $this->response();
|
||||
}
|
||||
throw new ClientException(
|
||||
$exception->getMessage(),
|
||||
SDK::SERVER_UNREACHABLE,
|
||||
$exception
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove redundant Query
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function cleanQuery()
|
||||
{
|
||||
if (isset($this->options['query']) && $this->options['query'] === []) {
|
||||
unset($this->options['query']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove redundant Headers
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function cleanFormParams()
|
||||
{
|
||||
if (isset($this->options['form_params']) && $this->options['form_params'] === []) {
|
||||
unset($this->options['form_params']);
|
||||
}
|
||||
}
|
||||
}
|
||||
335
app/Common/extend/alibabacloud/client/src/Request/RoaRequest.php
Executable file
335
app/Common/extend/alibabacloud/client/src/Request/RoaRequest.php
Executable file
@@ -0,0 +1,335 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Request;
|
||||
|
||||
use Exception;
|
||||
use Stringy\Stringy;
|
||||
use RuntimeException;
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\Encode;
|
||||
use AlibabaCloud\Client\Accept;
|
||||
use AlibabaCloud\Client\Support\Path;
|
||||
use AlibabaCloud\Client\Support\Sign;
|
||||
use AlibabaCloud\Client\Filter\Filter;
|
||||
use AlibabaCloud\Client\Support\Arrays;
|
||||
use AlibabaCloud\Client\Filter\ApiFilter;
|
||||
use AlibabaCloud\Client\Credentials\StsCredential;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
use AlibabaCloud\Client\Credentials\AccessKeyCredential;
|
||||
use AlibabaCloud\Client\Credentials\BearerTokenCredential;
|
||||
use AlibabaCloud\Client\Request\Traits\DeprecatedRoaTrait;
|
||||
|
||||
/**
|
||||
* RESTful ROA Request.
|
||||
*
|
||||
* @package AlibabaCloud\Client\Request
|
||||
* @method setParameter()
|
||||
*/
|
||||
class RoaRequest extends Request
|
||||
{
|
||||
use DeprecatedRoaTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $pathPattern = '/';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $pathParameters = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dateTimeFormat = "D, d M Y H:i:s \G\M\T";
|
||||
|
||||
/**
|
||||
* Resolve request parameter.
|
||||
*
|
||||
* @throws ClientException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function resolveParameter()
|
||||
{
|
||||
$this->resolveQuery();
|
||||
$this->resolveHeaders();
|
||||
$this->resolveBody();
|
||||
$this->resolveUri();
|
||||
$this->resolveSignature();
|
||||
}
|
||||
|
||||
private function resolveQuery()
|
||||
{
|
||||
if (!isset($this->options['query']['Version'])) {
|
||||
$this->options['query']['Version'] = $this->version;
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveBody()
|
||||
{
|
||||
// If the body has already been specified, it will not be resolved.
|
||||
if (isset($this->options['body'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($this->options['form_params'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Merge data, compatible with parameters set from constructor.
|
||||
$params = Arrays::merge(
|
||||
[
|
||||
$this->data,
|
||||
$this->options['form_params']
|
||||
]
|
||||
);
|
||||
|
||||
$this->encodeBody($params);
|
||||
|
||||
unset($this->options['form_params']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the body format based on the Content-Type and calculate the MD5 value.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
private function encodeBody(array $params)
|
||||
{
|
||||
$stringy = Stringy::create($this->options['headers']['Content-Type']);
|
||||
|
||||
if ($stringy->contains('application/json', false)) {
|
||||
$this->options['body'] = json_encode($params);
|
||||
$this->options['headers']['Content-MD5'] = base64_encode(md5($this->options['body'], true));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->options['body'] = Encode::create($params)->ksort()->toString();
|
||||
$this->options['headers']['Content-MD5'] = base64_encode(md5($this->options['body'], true));
|
||||
$this->options['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
* @throws Exception
|
||||
*/
|
||||
private function resolveHeaders()
|
||||
{
|
||||
$this->options['headers']['x-acs-version'] = $this->version;
|
||||
$this->options['headers']['x-acs-region-id'] = $this->realRegionId();
|
||||
$this->options['headers']['Date'] = gmdate($this->dateTimeFormat);
|
||||
|
||||
$signature = $this->httpClient()->getSignature();
|
||||
$this->options['headers']['x-acs-signature-method'] = $signature->getMethod();
|
||||
$this->options['headers']['x-acs-signature-nonce'] = Sign::uuid($this->product . $this->realRegionId());
|
||||
$this->options['headers']['x-acs-signature-version'] = $signature->getVersion();
|
||||
if ($signature->getType()) {
|
||||
$this->options['headers']['x-acs-signature-type'] = $signature->getType();
|
||||
}
|
||||
|
||||
$this->resolveAccept();
|
||||
$this->resolveContentType();
|
||||
$this->resolveSecurityToken();
|
||||
$this->resolveBearerToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ClientException
|
||||
* @throws Exception
|
||||
*/
|
||||
private function resolveSignature()
|
||||
{
|
||||
$this->options['headers']['Authorization'] = $this->signature();
|
||||
}
|
||||
|
||||
/**
|
||||
* If accept is not specified, it is determined by format.
|
||||
*/
|
||||
private function resolveAccept()
|
||||
{
|
||||
if (!isset($this->options['headers']['Accept'])) {
|
||||
$this->options['headers']['Accept'] = Accept::create($this->format)->toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the Content-Type is not specified, it is determined according to accept.
|
||||
*/
|
||||
private function resolveContentType()
|
||||
{
|
||||
if (!isset($this->options['headers']['Content-Type'])) {
|
||||
$this->options['headers']['Content-Type'] = "{$this->options['headers']['Accept']}; charset=utf-8";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
private function resolveSecurityToken()
|
||||
{
|
||||
if (!$this->credential() instanceof StsCredential) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->credential()->getSecurityToken()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->options['headers']['x-acs-security-token'] = $this->credential()->getSecurityToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
private function resolveBearerToken()
|
||||
{
|
||||
if ($this->credential() instanceof BearerTokenCredential) {
|
||||
$this->options['headers']['x-acs-bearer-token'] = $this->credential()->getBearerToken();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign the request message.
|
||||
*
|
||||
* @return string
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
private function signature()
|
||||
{
|
||||
/**
|
||||
* @var AccessKeyCredential $credential
|
||||
*/
|
||||
$credential = $this->credential();
|
||||
$access_key_id = $credential->getAccessKeyId();
|
||||
$signature = $this->httpClient()
|
||||
->getSignature()
|
||||
->sign(
|
||||
$this->stringToSign(),
|
||||
$credential->getAccessKeySecret()
|
||||
);
|
||||
|
||||
return "acs $access_key_id:$signature";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function resolveUri()
|
||||
{
|
||||
$path = Path::assign($this->pathPattern, $this->pathParameters);
|
||||
|
||||
$this->uri = $this->uri->withPath($path)
|
||||
->withQuery(
|
||||
$this->queryString()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function stringToSign()
|
||||
{
|
||||
$request = new \GuzzleHttp\Psr7\Request(
|
||||
$this->method,
|
||||
$this->uri,
|
||||
$this->options['headers']
|
||||
);
|
||||
|
||||
return Sign::roaString($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|string
|
||||
*/
|
||||
private function queryString()
|
||||
{
|
||||
$query = isset($this->options['query'])
|
||||
? $this->options['query']
|
||||
: [];
|
||||
|
||||
return Encode::create($query)->ksort()->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set path parameter by name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return RoaRequest
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function pathParameter($name, $value)
|
||||
{
|
||||
Filter::name($name);
|
||||
|
||||
if ($value === '') {
|
||||
throw new ClientException(
|
||||
'Value cannot be empty',
|
||||
SDK::INVALID_ARGUMENT
|
||||
);
|
||||
}
|
||||
|
||||
$this->pathParameters[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set path pattern.
|
||||
*
|
||||
* @param string $pattern
|
||||
*
|
||||
* @return self
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function pathPattern($pattern)
|
||||
{
|
||||
ApiFilter::pattern($pattern);
|
||||
|
||||
$this->pathPattern = $pattern;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method for set or get request parameters.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $arguments
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (strncmp($name, 'get', 3) === 0) {
|
||||
$parameter_name = \mb_strcut($name, 3);
|
||||
|
||||
return $this->__get($parameter_name);
|
||||
}
|
||||
|
||||
if (strncmp($name, 'with', 4) === 0) {
|
||||
$parameter_name = \mb_strcut($name, 4);
|
||||
$this->__set($parameter_name, $arguments[0]);
|
||||
$this->pathParameters[$parameter_name] = $arguments[0];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (strncmp($name, 'set', 3) === 0) {
|
||||
$parameter_name = \mb_strcut($name, 3);
|
||||
$with_method = "with$parameter_name";
|
||||
|
||||
throw new RuntimeException("Please use $with_method instead of $name");
|
||||
}
|
||||
|
||||
throw new RuntimeException('Call to undefined method ' . __CLASS__ . '::' . $name . '()');
|
||||
}
|
||||
}
|
||||
203
app/Common/extend/alibabacloud/client/src/Request/RpcRequest.php
Executable file
203
app/Common/extend/alibabacloud/client/src/Request/RpcRequest.php
Executable file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Request;
|
||||
|
||||
use Exception;
|
||||
use RuntimeException;
|
||||
use AlibabaCloud\Client\Support\Sign;
|
||||
use AlibabaCloud\Client\Support\Arrays;
|
||||
use AlibabaCloud\Client\Credentials\StsCredential;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
use AlibabaCloud\Client\Credentials\BearerTokenCredential;
|
||||
|
||||
/**
|
||||
* RESTful RPC Request.
|
||||
*
|
||||
* @package AlibabaCloud\Client\Request
|
||||
*/
|
||||
class RpcRequest extends Request
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
|
||||
|
||||
/**
|
||||
* Resolve request parameter.
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function resolveParameter()
|
||||
{
|
||||
$this->resolveBoolInParameters();
|
||||
$this->resolveCommonParameters();
|
||||
$this->repositionParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Boolean value to a string
|
||||
*/
|
||||
private function resolveBoolInParameters()
|
||||
{
|
||||
if (isset($this->options['query'])) {
|
||||
$this->options['query'] = array_map(
|
||||
static function ($value) {
|
||||
return self::boolToString($value);
|
||||
},
|
||||
$this->options['query']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Boolean value to a string.
|
||||
*
|
||||
* @param bool|string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function boolToString($value)
|
||||
{
|
||||
if (is_bool($value)) {
|
||||
return $value ? 'true' : 'false';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve Common Parameters.
|
||||
*
|
||||
* @throws ClientException
|
||||
* @throws Exception
|
||||
*/
|
||||
private function resolveCommonParameters()
|
||||
{
|
||||
$signature = $this->httpClient()->getSignature();
|
||||
$this->options['query']['RegionId'] = $this->realRegionId();
|
||||
$this->options['query']['Format'] = $this->format;
|
||||
$this->options['query']['SignatureMethod'] = $signature->getMethod();
|
||||
$this->options['query']['SignatureVersion'] = $signature->getVersion();
|
||||
$this->options['query']['SignatureNonce'] = Sign::uuid($this->product . $this->realRegionId());
|
||||
$this->options['query']['Timestamp'] = gmdate($this->dateTimeFormat);
|
||||
$this->options['query']['Action'] = $this->action;
|
||||
if ($this->credential()->getAccessKeyId()) {
|
||||
$this->options['query']['AccessKeyId'] = $this->credential()->getAccessKeyId();
|
||||
}
|
||||
if ($signature->getType()) {
|
||||
$this->options['query']['SignatureType'] = $signature->getType();
|
||||
}
|
||||
if (!isset($this->options['query']['Version'])) {
|
||||
$this->options['query']['Version'] = $this->version;
|
||||
}
|
||||
$this->resolveSecurityToken();
|
||||
$this->resolveBearerToken();
|
||||
$this->options['query']['Signature'] = $this->signature();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
private function resolveSecurityToken()
|
||||
{
|
||||
if (!$this->credential() instanceof StsCredential) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->credential()->getSecurityToken()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->options['query']['SecurityToken'] = $this->credential()->getSecurityToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
private function resolveBearerToken()
|
||||
{
|
||||
if ($this->credential() instanceof BearerTokenCredential) {
|
||||
$this->options['query']['BearerToken'] = $this->credential()->getBearerToken();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign the parameters.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
private function signature()
|
||||
{
|
||||
return $this->httpClient()
|
||||
->getSignature()
|
||||
->sign(
|
||||
$this->stringToSign(),
|
||||
$this->credential()->getAccessKeySecret() . '&'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function stringToSign()
|
||||
{
|
||||
$query = isset($this->options['query']) ? $this->options['query'] : [];
|
||||
$form_params = isset($this->options['form_params']) ? $this->options['form_params'] : [];
|
||||
$parameters = Arrays::merge([$query, $form_params]);
|
||||
|
||||
return Sign::rpcString($this->method, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust parameter position
|
||||
*/
|
||||
private function repositionParameters()
|
||||
{
|
||||
if ($this->method === 'POST' || $this->method === 'PUT') {
|
||||
foreach ($this->options['query'] as $api_key => $api_value) {
|
||||
$this->options['form_params'][$api_key] = $api_value;
|
||||
}
|
||||
unset($this->options['query']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method for set or get request parameters.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $arguments
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (strncmp($name, 'get', 3) === 0) {
|
||||
$parameter_name = \mb_strcut($name, 3);
|
||||
|
||||
return $this->__get($parameter_name);
|
||||
}
|
||||
|
||||
if (strncmp($name, 'with', 4) === 0) {
|
||||
$parameter_name = \mb_strcut($name, 4);
|
||||
$this->__set($parameter_name, $arguments[0]);
|
||||
$this->options['query'][$parameter_name] = $arguments[0];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (strncmp($name, 'set', 3) === 0) {
|
||||
$parameter_name = \mb_strcut($name, 3);
|
||||
$with_method = "with$parameter_name";
|
||||
|
||||
throw new RuntimeException("Please use $with_method instead of $name");
|
||||
}
|
||||
|
||||
throw new RuntimeException('Call to undefined method ' . __CLASS__ . '::' . $name . '()');
|
||||
}
|
||||
}
|
||||
237
app/Common/extend/alibabacloud/client/src/Request/Traits/AcsTrait.php
Executable file
237
app/Common/extend/alibabacloud/client/src/Request/Traits/AcsTrait.php
Executable file
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Request\Traits;
|
||||
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use AlibabaCloud\Client\SDK;
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Request\Request;
|
||||
use AlibabaCloud\Client\Filter\ApiFilter;
|
||||
use AlibabaCloud\Client\Regions\LocationService;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
|
||||
/**
|
||||
* Trait AcsTrait
|
||||
*
|
||||
* @package AlibabaCloud\Client\Request\Traits
|
||||
* @property Uri $uri
|
||||
* @mixin Request
|
||||
*/
|
||||
trait AcsTrait
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $version;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $product;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $action;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $serviceCode = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $endpointType = 'openAPI';
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $network = 'public';
|
||||
|
||||
/**
|
||||
* @var array|null
|
||||
*/
|
||||
public $endpointMap;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $endpointRegional;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $endpointSuffix = '';
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function action($action)
|
||||
{
|
||||
$this->action = ApiFilter::action($action);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param string $endpointSuffix
|
||||
*
|
||||
* @return AcsTrait
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function endpointSuffix($endpointSuffix)
|
||||
{
|
||||
$this->endpointSuffix = ApiFilter::endpointSuffix($endpointSuffix);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $network
|
||||
*/
|
||||
public function network($network)
|
||||
{
|
||||
$this->network = ApiFilter::network($network);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $version
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function version($version)
|
||||
{
|
||||
$this->version = ApiFilter::version($version);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $product
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function product($product)
|
||||
{
|
||||
$this->product = ApiFilter::product($product);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $endpointType
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function endpointType($endpointType)
|
||||
{
|
||||
$this->endpointType = ApiFilter::endpointType($endpointType);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $serviceCode
|
||||
*
|
||||
* @return $this
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function serviceCode($serviceCode)
|
||||
{
|
||||
$this->serviceCode = ApiFilter::serviceCode($serviceCode);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve Host.
|
||||
*
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
public function resolveHost()
|
||||
{
|
||||
// Return if specified
|
||||
if ($this->uri->getHost() !== 'localhost') {
|
||||
return;
|
||||
}
|
||||
|
||||
$region_id = $this->realRegionId();
|
||||
$host = '';
|
||||
|
||||
$this->resolveHostWays($host, $region_id);
|
||||
|
||||
if (!$host) {
|
||||
throw new ClientException(
|
||||
"No host found for {$this->product} in the {$region_id}, you can specify host by host() method. " .
|
||||
'Like $request->host(\'xxx.xxx.aliyuncs.com\')',
|
||||
SDK::HOST_NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
$this->uri = $this->uri->withHost($host);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $host
|
||||
* @param string $region_id
|
||||
*
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
private function resolveHostWays(&$host, $region_id)
|
||||
{
|
||||
// 1. Find host by map.
|
||||
if ($this->network === 'public' && isset($this->endpointMap[$region_id])) {
|
||||
$host = $this->endpointMap[$region_id];
|
||||
}
|
||||
|
||||
// 2. Find host by rules.
|
||||
if (!$host && $this->endpointRegional !== null) {
|
||||
$host = AlibabaCloud::resolveHostByRule($this);
|
||||
}
|
||||
|
||||
// 3. Find in the local array file.
|
||||
if (!$host) {
|
||||
$host = AlibabaCloud::resolveHost($this->product, $region_id);
|
||||
}
|
||||
|
||||
// 4. Find in the Location service.
|
||||
if (!$host && $this->serviceCode) {
|
||||
$host = LocationService::resolveHost($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function realRegionId()
|
||||
{
|
||||
if ($this->regionId !== null) {
|
||||
return $this->regionId;
|
||||
}
|
||||
|
||||
if ($this->httpClient()->regionId !== null) {
|
||||
return $this->httpClient()->regionId;
|
||||
}
|
||||
|
||||
if (AlibabaCloud::getDefaultRegionId() !== null) {
|
||||
return AlibabaCloud::getDefaultRegionId();
|
||||
}
|
||||
|
||||
throw new ClientException("Missing required 'RegionId' for Request", SDK::INVALID_REGION_ID);
|
||||
}
|
||||
}
|
||||
98
app/Common/extend/alibabacloud/client/src/Request/Traits/ClientTrait.php
Executable file
98
app/Common/extend/alibabacloud/client/src/Request/Traits/ClientTrait.php
Executable file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Request\Traits;
|
||||
|
||||
use AlibabaCloud\Client\AlibabaCloud;
|
||||
use AlibabaCloud\Client\Clients\Client;
|
||||
use AlibabaCloud\Client\Support\Arrays;
|
||||
use AlibabaCloud\Client\Request\Request;
|
||||
use AlibabaCloud\Client\Credentials\StsCredential;
|
||||
use AlibabaCloud\Client\Exception\ClientException;
|
||||
use AlibabaCloud\Client\Exception\ServerException;
|
||||
use AlibabaCloud\Client\Credentials\AccessKeyCredential;
|
||||
use AlibabaCloud\Client\Credentials\Requests\AssumeRole;
|
||||
use AlibabaCloud\Client\Credentials\CredentialsInterface;
|
||||
use AlibabaCloud\Client\Credentials\BearerTokenCredential;
|
||||
use AlibabaCloud\Client\Credentials\Providers\CredentialsProvider;
|
||||
use AlibabaCloud\Client\Credentials\Requests\GenerateSessionAccessKey;
|
||||
|
||||
/**
|
||||
* Trait ClientTrait
|
||||
*
|
||||
* @package AlibabaCloud\Client\Request\Traits
|
||||
*
|
||||
* @mixin Request
|
||||
*/
|
||||
trait ClientTrait
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $config = [];
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
*/
|
||||
public static function config(array $config)
|
||||
{
|
||||
self::$config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return credentials directly if it is an AssumeRole or GenerateSessionAccessKey.
|
||||
*
|
||||
* @return AccessKeyCredential|BearerTokenCredential|CredentialsInterface|StsCredential
|
||||
* @throws ClientException
|
||||
* @throws ServerException
|
||||
*/
|
||||
public function credential()
|
||||
{
|
||||
if ($this instanceof AssumeRole || $this instanceof GenerateSessionAccessKey) {
|
||||
return $this->httpClient()->getCredential();
|
||||
}
|
||||
|
||||
$timeout = isset($this->options['timeout'])
|
||||
? $this->options['timeout']
|
||||
: Request::TIMEOUT;
|
||||
|
||||
$connectTimeout = isset($this->options['connect_timeout'])
|
||||
? $this->options['connect_timeout']
|
||||
: Request::CONNECT_TIMEOUT;
|
||||
|
||||
return $this->httpClient()->getSessionCredential($timeout, $connectTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the client based on the request's settings.
|
||||
*
|
||||
* @return Client
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function httpClient()
|
||||
{
|
||||
if (!AlibabaCloud::all()) {
|
||||
if (CredentialsProvider::hasCustomChain()) {
|
||||
CredentialsProvider::customProvider($this->client);
|
||||
} else {
|
||||
CredentialsProvider::defaultProvider($this->client);
|
||||
}
|
||||
}
|
||||
|
||||
return AlibabaCloud::get($this->client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merged with the client's options, the same name will be overwritten.
|
||||
*
|
||||
* @throws ClientException
|
||||
*/
|
||||
public function mergeOptionsIntoClient()
|
||||
{
|
||||
$this->options = Arrays::merge(
|
||||
[
|
||||
$this->httpClient()->options,
|
||||
$this->options
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Client\Request\Traits;
|
||||
|
||||
/**
|
||||
* @package AlibabaCloud\Client\Request\Traits
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
trait DeprecatedRoaTrait
|
||||
{
|
||||
/**
|
||||
* @param $name
|
||||
* @param $value
|
||||
*
|
||||
* @return $this
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function putPathParameter($name, $value)
|
||||
{
|
||||
return $this->pathParameter($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pathPattern
|
||||
*
|
||||
* @return $this
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function setUriPattern($pathPattern)
|
||||
{
|
||||
return $this->pathPattern($pathPattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getUriPattern()
|
||||
{
|
||||
return $this->pathPattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @deprecated
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getPathParameters()
|
||||
{
|
||||
return $this->pathParameters;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user