feat: get_ip_addr

This commit is contained in:
dawnwinterLiu 2023-08-02 14:37:52 +08:00
parent 572fd894c9
commit cdbe33b15f
2 changed files with 19 additions and 1 deletions

View File

@ -54,7 +54,8 @@
generate_random_gps/3,
nmea0183_frame/1,
towgs84/2,
fromwgs84/2
fromwgs84/2,
get_ip_addr/1
]).
%%//
@ -367,6 +368,22 @@ get_baidu_addr(AK, Coordtype, Lng, Lat) ->
#{}
end.
get_ip_addr(Ip) ->
AppKey =
case dgiot_data:get(dgiot_configuration, baidu_sak) of
not_find ->
dgiot_utils:to_binary(application:get_env(dgiot_http, baidumap_appkey, <<"">>));
Ak ->
Ak
end,
Url = "https://api.map.baidu.com/location/ip?ip=" ++ dgiot_utils:to_list(Ip) ++ "&coor=bd09ll&ak=" ++ dgiot_utils:to_list(AppKey),
case dgiot_http_client:request(get, {Url, []}) of
{ok, #{<<"status">> := 0, <<"content">> := #{<<"address">> := Address}}} ->
Address;
_Error ->
Ip
end.
%%#
%%# base_log
%%# base_lat

View File

@ -137,6 +137,7 @@ alter_table(#{<<"tableName">> := TableName}, #{<<"channel">> := Channel} = Conte
pass
end.
%% ALTER TABLE _24b9b4bc50._5392ccb3d7 drop COLUMN status;
get_addSql(ProductId, TdColumn, Database, TableName) ->
case dgiot_product:lookup_prod(ProductId) of
{ok, #{<<"thing">> := #{<<"properties">> := Props} = Thing}} ->