Merge pull request #583 from dgiot/yuhang

工厂
This commit is contained in:
dawnwinterLiu 2022-08-25 18:14:19 +08:00 committed by GitHub
commit 5944fe2b85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 30 deletions

View File

@ -31,8 +31,7 @@ wechat.secret = 0c8b9e229ebe48c6878727a9d2e0263d
tencent_sms.appid = 1400635630
tencent_sms.appkey = 40d9609b9e6212cbff051b4f1d4cabfc
tencent_sms.notification.templateId = 1473069
tencent_sms.sign = ae746ee803
tencent_sms.branchId = ae746ee803
# jwt
jwt.algorithm = rs256

View File

@ -42,11 +42,10 @@
{datatype, string}
]}.
{mapping, "tencent_sms.sign", "dgiot_http.tencent_sms_sign", [
{mapping, "tencent_sms.branchId", "dgiot_http.tencent_sms_branchId", [
{default, "ae746ee803"},
{datatype, string}
]}.
%%--------------------------------------------------------------------
%% 百度地图配置
%%--------------------------------------------------------------------

View File

@ -40,6 +40,11 @@
"example": "1473069"
},
"sign": {
"required": true,
"type": "string",
"example": "质云科技"
},
"branchId": {
"required": true,
"type": "string",
"example": "ae746ee803"
@ -99,16 +104,16 @@
"type": "string",
"example": "dasssd54"
},
"dailyWorksId": {
"required": true,
"type": "string",
"example": "abcd"
},
"department": {
"required": true,
"type": "string",
"example": "部门"
},
"dailyWorksId": {
"required": true,
"type": "string",
"example": "每天工单编号"
},
"branchId": {
"required": true,
"type": "string",

View File

@ -76,16 +76,17 @@ do_request(get_file_signature, Args, _Context, _Req) ->
%dgiot通用告警
do_request(post_handlewarnsendsms, #{<<"appId">> := AppId, <<"appKey">> := AppKey, <<"tplId">> := TplId, <<"sign">> := Sign, <<"params">> := Params}, _Context, _Req) ->
do_request(post_handlewarnsendsms, #{<<"appId">> := AppId, <<"appKey">> := AppKey,<<"sign">> := Sign,<<"tplId">> := TplId, <<"params">> := Params,<<"branchId">> := BranchId}, _Context, _Req) ->
%
application:set_env(dgiot_http, tencent_sms_appid, AppId),
application:set_env(dgiot_http, tencent_sms_appkey, AppKey),
application:set_env(dgiot_http, tencent_sms_notification_templateId, TplId),
%
application:set_env(dgiot_http, tencent_sms_sign, Sign),
%
application:set_env(dgiot_http, tencent_sms_params, Params),
application:set_env(dgiot_http, tencent_sms_BranchId, BranchId),
case dgiot_parse:get_object(<<"_Role">>, Sign) of
case dgiot_parse:get_object(<<"_Role">>, BranchId) of
{ok, #{<<"objectId">> := RolesId}} ->
%
Users = dgiot_parse_auth:get_UserIds(unicode:characters_to_binary(RolesId)),
@ -93,8 +94,8 @@ do_request(post_handlewarnsendsms, #{<<"appId">> := AppId, <<"appKey">> := AppKe
{ok, #{<<"results">> := Row}} = dgiot_parse:query_object(<<"_User">>, UsersQuery),
PhoneList = lists:foldl(fun(X, Acc) ->
Phone = unicode:characters_to_binary(dgiot_utils:to_list(maps:get(<<"phone">>, X))),
dgiot_notification:send_sms(Phone, application:get_env(dgiot_http, tencent_sms_params, Params)),
Acc ++ [unicode:characters_to_binary(dgiot_utils:to_list(maps:get(<<"phone">>, X)))]
Data=dgiot_notification:send_sms(Phone, application:get_env(dgiot_http, tencent_sms_params, Params)),
Acc ++ [Data]
end, [], Row),
% {1} {2}{3}{4}{5},:{6}
Json = #{<<"phones">> => PhoneList},
@ -108,7 +109,7 @@ do_request(post_handlewarnsendsms, #{<<"appId">> := AppId, <<"appKey">> := AppKe
end;
%
do_request(post_warnsendsms, #{<<"objectId">> := DeviceId, <<"department">> := Department,<<"dailyWorksId">>:= DailyWorksId,<<"branchId">> := BranchId,<<"datetimes">> := DateTimes, <<"docnumber">> := Docnumber, <<"username">> := UserName, <<"workshop">> := Workshop, <<"level">> := Level, <<"desc">> := Desc, <<"file">> := FileInfo}, _Context, _Req) ->
do_request(post_warnsendsms, #{<<"objectId">> := DeviceId,<<"department">>:=Department,<<"dailyWorksId">>:=DailyWorksId,<<"branchId">> := BranchId,<<"datetimes">> := DateTimes, <<"docnumber">> := Docnumber, <<"username">> := UserName, <<"workshop">> := Workshop, <<"level">> := Level, <<"desc">> := Desc, <<"file">> := FileInfo}, _Context, _Req) ->
case Level of
<<"1">> ->
Warn = <<"待首检"/utf8>>,
@ -131,8 +132,8 @@ do_request(post_warnsendsms, #{<<"objectId">> := DeviceId, <<"department">> := D
<<"content">> => #{
<<"alarm">> => #{
<<"deviceId"/utf8>> => DeviceId,
<<"dailyWorksId"/utf8>> => DailyWorksId,
<<"department"/utf8>> => Department,
<<"dailyWorksId"/utf8>> => DailyWorksId,
<<"docnumber"/utf8>> => Docnumber,
<<"datetimes"/utf8>> => DateTimes,
<<"username"/utf8>> => UserName,
@ -156,8 +157,8 @@ do_request(post_warnsendsms, #{<<"objectId">> := DeviceId, <<"department">> := D
{ok, #{<<"results">> := Row}} = dgiot_parse:query_object(<<"_User">>, UsersQuery),
PhoneList = lists:foldl(fun(X, Acc) ->
Phone = unicode:characters_to_binary(dgiot_utils:to_list(maps:get(<<"phone">>, X))),
dgiot_notification:send_sms(Phone, [DateTimes, <<"-">>, UserName, Docnumber, Workshop, Warns]),
Acc ++ [unicode:characters_to_binary(dgiot_utils:to_list(maps:get(<<"phone">>, X)))]
Data=dgiot_notification:send_sms(Phone, [DateTimes, <<"-">>, UserName, Docnumber, Workshop, Warns]),
Acc ++ [Data]
end, [], Row),
% {1} {2}{3}{4}{5},:{6}
Json = #{<<"phones">> => PhoneList},

View File

@ -21,7 +21,7 @@
-dgiot_data("ets").
-export([init_ets/0]).
%% API
-export([send_sms/2, send_sms/3, send_sms/5, send_sms/6, send_sms/7]).
-export([send_sms/2, send_sms/3, send_sms/7, send_sms/8]).
-export([send_email/1, test_email/0]).
@ -64,15 +64,14 @@ check_verification_code(Key, Code) ->
send_sms(Mobile, Params) ->
send_sms("+86", Mobile, Params).
send_sms(NationCode, Mobile, Params) ->
TplId = dgiot_utils:to_list(application:get_env(dgiot_http, tencent_sms_notification_templateId, <<"">>)),
AppId = dgiot_utils:to_list(application:get_env(dgiot_http, tencent_sms_appid, <<"">>)),
AppKey = dgiot_utils:to_list(application:get_env(dgiot_http, tencent_sms_appkey, <<"">>)),
send_sms(NationCode, Mobile, Params, AppId, AppKey, TplId).
send_sms(Mobile, Params, AppId, AppKey, TplId) ->
send_sms("+86", Mobile, Params, AppId, AppKey, TplId, <<>>).
send_sms(NationCode, Mobile, Params, AppId, AppKey, TplId) ->
send_sms(NationCode, Mobile, Params, AppId, AppKey, TplId, <<>>).
send_sms(NationCode, Mobile, Params, AppId, AppKey, TplId, Ext) ->
AppId = unicode:characters_to_binary(application:get_env(dgiot_http, tencent_sms_appid, <<"1400635630">>)),
AppKey = unicode:characters_to_binary(application:get_env(dgiot_http, tencent_sms_appkey, <<"40d9609b9e6212cbff051b4f1d4cabfc">>)),
Sign = unicode:characters_to_binary(application:get_env(dgiot_http, tencent_sms_sign, <<"质云科技"/utf8>>)),
TplId = unicode:characters_to_binary(application:get_env(dgiot_http, tencent_sms_notification_templateId, <<"1473069">>)),
send_sms(NationCode,Mobile,AppId,AppKey,Sign,TplId,Params).
send_sms(NationCode,Mobile,AppId,AppKey,Sign,TplId,Params) ->
send_sms(NationCode,Mobile,AppId,AppKey,Sign,TplId,Params, <<>>).
send_sms(NationCode,Mobile,AppId,AppKey,Sign,TplId,Params, Ext) ->
AppId_b =
case is_binary(AppId) of
true ->
@ -81,6 +80,9 @@ send_sms(NationCode, Mobile, Params, AppId, AppKey, TplId, Ext) ->
AppId
end,
Random = dgiot_utils:to_list(1000 + rand:uniform(1000)),
io:fwrite("1111111111111111"),
io:fwrite(Sign),
io:fwrite("1111111111111111"),
Url =
case is_list(Mobile) of
true ->
@ -114,7 +116,7 @@ send_sms(NationCode, Mobile, Params, AppId, AppKey, TplId, Ext) ->
AppKey
end,
SigStr = io_lib:format("appkey=~s&random=~s&time=~s&mobile=~s", [AppKey_b, Random, integer_to_list(Now), MobileStr]),
Sig_b = dgiot_utils:to_binary(string:to_lower(binary_to_list(<<<<Y>> || <<X:4>> <= crypto:hash(sha256, SigStr), Y <- integer_to_list(X, 16)>>))),
Sig_b = unicode:characters_to_binary(string:to_lower(binary_to_list(<<<<Y>> || <<X:4>> <= crypto:hash(sha256, SigStr), Y <- integer_to_list(X, 16)>>))),
FunParams =
fun(X, Acc) ->
case is_binary(X) of
@ -136,7 +138,7 @@ send_sms(NationCode, Mobile, Params, AppId, AppKey, TplId, Ext) ->
<<"ext">> => Ext,
<<"extend">> => <<>>,
<<"params">> => Params_b,
<<"sign">> => <<"dgiot"/utf8>>,
<<"sign">> => Sign,
<<"tel">> => Tel_b,
<<"time">> => Now,
<<"sig">> => Sig_b