短信验证码更新

1.更新permission release分支

2.在beemq管理界面参数配置-增加配置

  1. 添加组件 systemConfig
  2. 添加以下两个配置项
    # 是否启用短信验证码登录,true为启用
    SMSVerificationCodeEnable=true
    # 短信验证码有效期 单位毫秒
    validitySMSVerificationCode=60000
    

3.导入脚本

INSERT INTO public.bee_idx_comm (id, name, pid, status, path, val, time) VALUES (2146241176, 'GetSystemConfigListScript', 490763255, '0', 'root/script/GetSystemConfigListScript', '{"param":"{}","name":"GetSystemConfigListScript","publicClass":"com.kingsware.fun.GetSystemConfigListScript","script":"package com.kingsware.fun;\r\n\r\nimport com.alibaba.fastjson.JSON;\r\nimport com.alibaba.fastjson.JSONArray;\r\nimport com.alibaba.fastjson.JSONObject;\r\nimport com.kingsware.env.pojo.CollectResult;\r\nimport com.kingsware.env.script.KBaseMain;\r\nimport com.kingsware.socket.client.KEnvClient;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\n/**\r\n * @program: us\r\n * @Date: 2021/11/25 17:17\r\n * @Author: leimingming\r\n * @Description: 获取通用的配置参数列表\r\n */\r\npublic class GetSystemConfigListScript extends KBaseMain<Object> {\r\n\r\n    @Override\r\n    public CollectResult mainEx(Object o, KEnvClient kEnvClient) throws Exception {\r\n        CollectResult collectResult = new CollectResult();\r\n\r\n        String search = kEnvClient.search(\"root/config/assembly/systemConfig/prop/*\");\r\n        println(search);\r\n\r\n        List<JSONObject> result = new ArrayList<>();\r\n\r\n        JSONArray array = JSON.parseArray(search);\r\n        for (int i = 0; i < array.size(); i++) {\r\n            JSONObject object = array.getJSONObject(i);\r\n            String nId = object.getString(\"nId\");\r\n            String val = object.getString(\"val\");\r\n            String path = object.getString(\"path\");\r\n\r\n            String descResult = kEnvClient.getVal(path + \"/desc\");\r\n            JSONObject descObject = JSON.parseObject(descResult);\r\n            String desc = descObject == null ? \"unknown\" : descObject.getString(\"value\");\r\n\r\n            println(nId+\"--\"+val+\"--\"+desc);\r\n\r\n            JSONObject config = new JSONObject();\r\n            config.put(\"key\",nId);\r\n            config.put(\"value\",val);\r\n            config.put(\"desc\",desc);\r\n\r\n            result.add(config);\r\n        }\r\n\r\n        collectResult.setResult(result);\r\n        return collectResult;\r\n    }\r\n}\r\n"}', '2021-11-25 17:41:47.535000');

4.插入网关

INSERT INTO "BasicGatewayRoute"(uuid,name,sourcepath,targetpath,logtype,logcontent,"createTime","state","updateTime",verify,"moduleId","type")
VALUES('3a550f57-5315-4d32-9871-2f06f835e3ed','发送短信验证码','/ops/system/user/sendSMSVerificationCode','/permission/user/sendSMSVerificationCode','操作','发送短信验证码','2021-11-23 10:01:01',0,'2021-11-23 10:01:01',false,'uuidpermission','normal');

INSERT INTO public."BasicGatewayRoute" (uuid, name, sourcepath, module, targeturl, targetpath, logtype, logcontent, param, responsebody, remark, "createTime", state, "updateTime", verify, type, "moduleId") VALUES ('ebe3e3de-f688-61a5-8b1e-f32706c45625', '获取系统全局配置', '/ops/getSystemConfigList', null, null, 'GetSystemConfigListScript', '查询', '', '', '', '', '2021-11-25 17:53:12', 0, '2021-11-25 17:53:12', false,'script','c321b0458d914c5c818896d41d1ad3e1');

浏览器访问更新路由

http://{ip}:{port}/ops/route/init

5.需在二开平台实现 名称为:SMSVerificationCode 的脚本,在脚本中实现给客户发送短信验证码的功能

参数为

{
    "name":"系统管理员",
    "username":"admin",
    "phone":"13112345678"
}

返回值为发送的验证码

以下为示例

package com.kingsware.fun;

import com.kingsware.env.pojo.CollectResult;
import com.kingsware.env.script.KBaseMain;
import com.kingsware.socket.client.KEnvClient;
import org.apache.commons.lang3.RandomStringUtils;

/**
 * @program: us
 * @Date: 2021/11/22 16:21
 * @Author: leimingming
 * @Description: 短信验证码发送实现类
 */
class UserParam{
    private String name;
    private String username;
    private String phone;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}

public class SMSVerificationCode extends KBaseMain<UserParam> {

    @Override
    public CollectResult mainEx(UserParam userParam, KEnvClient kEnvClient) throws Exception {

        //获取验证码
        String s = RandomStringUtils.randomNumeric(6);
        //发送短信

        //根据发送结果,将验证码返回至permission
        CollectResult collectResult = new CollectResult();
        collectResult.setResult(s);

        return collectResult;
    }
}