From 2dc7af049a20797b09a501af980d2e30b61b4639 Mon Sep 17 00:00:00 2001 From: qingn1 <1729727316@qq.com> Date: Thu, 25 Aug 2022 18:01:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=8E=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/dgiot_http/etc/dgiot_http.conf | 3 +-- apps/dgiot_http/priv/dgiot_http.schema | 3 +-- .../dgiot_http/priv/swagger/swagger_http.json | 15 +++++++---- apps/dgiot_http/src/dgiot_http_handler.erl | 19 +++++++------- .../src/umeng/dgiot_notification.erl | 26 ++++++++++--------- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/apps/dgiot_http/etc/dgiot_http.conf b/apps/dgiot_http/etc/dgiot_http.conf index 4ef7eaa3..eaeecd43 100644 --- a/apps/dgiot_http/etc/dgiot_http.conf +++ b/apps/dgiot_http/etc/dgiot_http.conf @@ -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 diff --git a/apps/dgiot_http/priv/dgiot_http.schema b/apps/dgiot_http/priv/dgiot_http.schema index ccc48c8b..65c85288 100644 --- a/apps/dgiot_http/priv/dgiot_http.schema +++ b/apps/dgiot_http/priv/dgiot_http.schema @@ -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} ]}. - %%-------------------------------------------------------------------- %% 百度地图配置 %%-------------------------------------------------------------------- diff --git a/apps/dgiot_http/priv/swagger/swagger_http.json b/apps/dgiot_http/priv/swagger/swagger_http.json index 4f664602..e0fea782 100644 --- a/apps/dgiot_http/priv/swagger/swagger_http.json +++ b/apps/dgiot_http/priv/swagger/swagger_http.json @@ -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", diff --git a/apps/dgiot_http/src/dgiot_http_handler.erl b/apps/dgiot_http/src/dgiot_http_handler.erl index f194399e..3e4d9ec3 100644 --- a/apps/dgiot_http/src/dgiot_http_handler.erl +++ b/apps/dgiot_http/src/dgiot_http_handler.erl @@ -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}, diff --git a/apps/dgiot_http/src/umeng/dgiot_notification.erl b/apps/dgiot_http/src/umeng/dgiot_notification.erl index c76c01ab..b640c25a 100644 --- a/apps/dgiot_http/src/umeng/dgiot_notification.erl +++ b/apps/dgiot_http/src/umeng/dgiot_notification.erl @@ -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(<<<> || <> <= crypto:hash(sha256, SigStr), Y <- integer_to_list(X, 16)>>))), + Sig_b = unicode:characters_to_binary(string:to_lower(binary_to_list(<<<> || <> <= 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