package cn.iocoder.yudao.framework.http.sms;

import cn.iocoder.yudao.framework.http.core.Request;
import cn.iocoder.yudao.framework.http.core.Response;
import cn.iocoder.yudao.framework.http.util.HttpUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * BulksmsHttp 类用于处理与 Bulksms 相关的 HTTP 请求。
 * 主要功能包括发送短信和设置短信参数。
 *
 * @author wuxian
 * @since 2024-11-27
 **/
@Slf4j
public class BulksmsHttp {
    // 请求的URL地址
    private static final String REQ_URL = "https://portal.nigeriabulksms.com/api/";

    /**
     * 发送请求到 Bulksms 服务器。
     *
     * @param param 请求参数
     * @return 响应对象
     */
    public Response sendReq(Map<String, Object> param) {
        // 设置请求头
        Map<String, String> header = new HashMap<>();
        header.put("Accept", "text/html,application/xhtml+xml,application/xml");
        header.put("Content-Type", "application/json");
        // 发送POST请求
        return HttpUtils.post(REQ_URL, param, header, Request.ParamFormat.FORM);
    }

    /**
     * 设置发送短信的参数。
     *
     * @param mobiles    接收短信的手机号
     * @param message    短信内容
     * @param senderName 发送者名称
     * @param username   用户名
     * @param password   密码
     * @return 参数映射
     */
    public Map<String, Object> setParams(String mobiles, String message, String senderName, String username, String password) {
        Map<String, Object> param = new HashMap<>();
        param.put("username", username);
        param.put("password", password);
        param.put("mobiles", mobiles);
        param.put("message", message);
        param.put("sender", senderName);
        return param;
    }

    public static void main(String[] args) {
        BulksmsHttp test = new BulksmsHttp();

        String mobiles = "2347087010202";
        String sender = "ECLogistics";
        String message = "Good day This is E&C logistics(ship from China to Nigeria),It has been a while since we last worked together,and we would like to reestablish our partnership. Our main service:GROUPAGE/FULL CONTAINER/AIR CARGO/COMPRESSING/CONSOLITAION .We value your business and would appreciate the opportunity to serve you once again.Have a Nice day! My WA :+861 592 035 652 7";
        String username = "ecit@ewchina.net";
        String password = "0z@@vtj1h";

        Map<String, Object> param = test.setParams(mobiles, sender, message, username, password);

        test.sendReq(param);
    }

}
