网易云短信接口调入(java)

1 需要两个jar包  httpclient-4.3.6.jar和httpcore-4.3.3.jar jar包

 

2.验证码生成工具

public class CheckSumBuilder {
    //计算并获取checkSum
    public static String getCheckSum(String appSecret, String nonce, String curTime) {
        return encode("SHA", appSecret + nonce + curTime);
    }

    private static String encode(String algorithm, String value) {
        if (value == null) {
            return null;
        }

        try {
            MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
            messageDigest.update(value.getBytes());
            return getFormattedText(messageDigest.digest());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private static String getFormattedText(byte[] bytes) {
        int len = bytes.length;
        StringBuilder sb = new StringBuilder(len * 2);
        for (int $i = 0; $i < len; $i++) {
            sb.append(HEX_DIGITS[(bytes[$i] >> 4) & 0x0f]);
            sb.append(HEX_DIGITS[bytes[$i] & 0x0f]);
        }
        return sb.toString();
    }

    private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

}

3.(1)验证码

 

public class SendCode {

    //发送验证码的请求路径URL
    private static final String
            SERVER_URL="xxxxxxxxxx";
    //网易云信分配的账号,请替换你在管理后台应用下申请的Appkey
    private static final String
            APP_KEY="xxxxxxxxxxxxxx";
    //网易云信分配的密钥,请替换你在管理后台应用下申请的appSecret
    private static final String APP_SECRET="xxxxxxxxxxxx";
    //随机数
    private static final String NONCE="123456";
    //短信模板ID
    private static final String TEMPLATEID="xxxxxxxxx";
    //验证码长度,范围4~10,默认为4
    private static final String CODELEN="6";

    // MOBILE 手机号
    public static void sendCode(String MOBILE) throws Exception {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(SERVER_URL);
        String curTime = String.valueOf((new Date()).getTime() / 1000L);
        /*
         * 参考计算CheckSum的java代码,在上述文档的参数列表中,有CheckSum的计算文档示例
         */
        String checkSum = CheckSumBuilder.getCheckSum(APP_SECRET, NONCE, curTime);

        // 设置请求的header
        httpPost.addHeader("AppKey", APP_KEY);
        httpPost.addHeader("Nonce", NONCE);
        httpPost.addHeader("CurTime", curTime);
        httpPost.addHeader("CheckSum", checkSum);
        httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");

        // 设置请求的的参数,requestBody参数
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        /*
         * 1.如果是模板短信,请注意参数mobile是有s的,详细参数配置请参考“发送模板短信文档”
         * 2.参数格式是jsonArray的格式,例如 "['13888888888','13666666666']"
         * 3.params是根据你模板里面有几个参数,那里面的参数也是jsonArray格式
         */
        nvps.add(new BasicNameValuePair("templateid", TEMPLATEID));
        nvps.add(new BasicNameValuePair("mobile",  MOBILE.toString()));     //JSON.toJSONString(MOBILE))  )
        nvps.add(new BasicNameValuePair("codeLen", CODELEN));

        httpPost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));

        // 执行请求
        HttpResponse response = httpClient.execute(httpPost);
        /*
         * 1.打印执行结果,打印结果一般会200、315、403、404、413、414、500
         * 2.具体的code有问题的可以参考官网的Code状态表
         */
        System.out.println(EntityUtils.toString(response.getEntity(), "utf-8"));
    }


}

3.(2)通知类或运用类 


public class SendNoticeCode {

    //发送验证码的请求路径URL
    private static final String
            SERVER_URL="xxxxxxxxxx";
    //网易云信分配的账号,请替换你在管理后台应用下申请的Appkey
    private static final String
            APP_KEY="xxxxxxxxxxxxxxxxxxxxxxxx";
    //网易云信分配的密钥,请替换你在管理后台应用下申请的appSecret
    private static final String APP_SECRET="xxxxxxxxxxxxxxxxxx";
    //随机数
    private static final String NONCE="123456";
    //短信模板ID
    private static final String TEMPLATEID="xxxxxxxxxxxxxxxxx";

    //MOBILES       手机号,接收者号码列表,JSONArray格式,限制接收者号码个数最多为100个
    //PARAMS        短信参数列表,用于依次填充模板,JSONArray格式,每个变量长度不能超过30字,对于不包含变量的模板,不填此参数表示模板即短信全文内容
    public static void sendNoticeCode(String MOBILES, String PARAMS) throws Exception{

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(SERVER_URL);
        String curTime = String.valueOf((new Date()).getTime() / 1000L);
        /*
         * 参考计算CheckSum的java代码,在上述文档的参数列表中,有CheckSum的计算文档示例
         */
        String checkSum = CheckSumBuilder.getCheckSum(APP_SECRET, NONCE, curTime);

        // 设置请求的header
        httpPost.addHeader("AppKey", APP_KEY);
        httpPost.addHeader("Nonce", NONCE);
        httpPost.addHeader("CurTime", curTime);
        httpPost.addHeader("CheckSum", checkSum);
        httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");

        // 设置请求的的参数,requestBody参数
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        /*
         * 1.如果是模板短信,请注意参数mobile是有s的,详细参数配置请参考“发送模板短信文档”
         * 2.参数格式是jsonArray的格式,例如 "['13888888888','13666666666']"
         * 3.params是根据你模板里面有几个参数,那里面的参数也是jsonArray格式
         */
        nvps.add(new BasicNameValuePair("templateid", TEMPLATEID));
        nvps.add(new BasicNameValuePair("mobiles", MOBILES));
        nvps.add(new BasicNameValuePair("params", PARAMS));

        httpPost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));

        // 执行请求
        HttpResponse response = httpClient.execute(httpPost);
        /*
         * 1.打印执行结果,打印结果一般会200、315、403、404、413、414、500
         * 2.具体的code有问题的可以参考官网的Code状态表
         */
        System.out.println(EntityUtils.toString(response.getEntity(), "utf-8"));
}

    public static void main(String[] args) throws Exception {
        SendNoticeCode sen = new SendNoticeCode();
        sen.sendNoticeCode( "['13888888888','13666666666']", "['xxxx','xxxx']");
    }

}

附发送多人,编辑发送内容 



        //电话号码
		JSONArray json = new JSONArray();
		json.add("151****7851");
		
		//短信内容(此处的短信内容是你在网易短信模板申请中的变量【%s】这种,
		//值得注意的是你申请了多少个%S变量就必须填写多少个但是每个变量不能大于30个字:比如我申请 
         了11个那么我就要传11个变量)
		//如果参数少了会提示{"code":414,"msg":"miss param"}大概意思是说缺少参数
		JSONArray json1 = new JSONArray();

		//json1.add("222");
		//json1.add("https:www.dingteam.com");
		
		
		System.out.println(json1.toString());
		
		//json.add(value)
		List<NameValuePair> nvp = new ArrayList<NameValuePair>();
		nvp.add(new BasicNameValuePair("templateid",TEMPLATEID));
		
		nvp.add(new BasicNameValuePair("mobiles","[\"187709***\"]"));
		
		nvp.add(new BasicNameValuePair("params",json1.toString()));
		
	
		
		httpPost.setEntity(new UrlEncodedFormEntity(nvp,"utf-8"));
		
		HttpResponse response = httpCline.execute(httpPost);
		 
		System.out.println(EntityUtils.toString(response.getEntity(), "utf-8"));

	}
### 实现与金蝶星空云ERP系统的入库接口集成 为了实现与其他系统的入库操作对接,可以利用轻易云数据集成平台来构建集成方案。具体来说,在创建集成方案时需指定源业务系统为金蝶云星空并选择相应的连接器。 对于其他入库单的处理,应选取“其他入库查询接口”作为数据获取端口,并设置目标系统为欲对接的应用(如积加ERP),同时选定该应用内的“创建其他入库单接口”用于执行入库动作[^1]。此过程同样适用于采购入库场景下的不同ERP系统间的交互,例如将金蝶云星空中的采购入库信息同步至旺店通·企业版中完成相应记录的建立[^2]。 当涉及到更复杂的业务流程,比如管易云同金蝶云星空之间有关于采购入库单以及分步式调入单之间的衔接,则可通过定义详细的映射关系确保两套系统内相同业务逻辑的一致性和连贯性[^3]。而在面对更为广泛的电商环境时,针对像管易云这样的电商平台管理系统,其与金蝶云星空之间的对接不仅限于简单的库存变动通知,还括订单处理、物流跟踪等一系列增值服务的支持[^4]。 ```python def integrate_inventory_entry(source_system, target_system): """ 集成两个系统之间的入库功能 参数: source_system (str): 源系统名称 target_system (str): 目标系统名称 返回: str: 成功消息或错误描述 """ try: # 建立轻松云数据集成平台会话 session = EasyCloudSession() # 创建新的集成方案 integration_plan = IntegrationPlan( name=f"{source_system}_to_{target_system}", description="自动化的入库单据流转" ) # 添加源系统配置项 add_source_config(integration_plan, system=source_system) # 设置目的系统参数 set_target_params(integration_plan, system=target_system) # 提交计划以激活服务 submit_integration_plan(session, integration_plan) return "Integration plan created and activated successfully." except Exception as e: return f"Failed to create or activate the integration plan due to {e}" ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值