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.core.client.HttpClient;
import cn.iocoder.yudao.framework.http.core.client.HttpClientFactory;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wuxian
 * @since 2024-10-23
 **/
@Slf4j
public class WhisperClientHttp {

    public void testPost(){
//        HttpResponse<String> response = Unirest.post("https://whispersms.xyz/api/send_message/")
//                .header("Authorization", "Api_key gAAAAABl5ZDpoKnKVaK0scmWo7GQeKDA1sn3OZBeMXUz211vZv5QqSEtr7_LD5ISTqSD0PnWLRWavYmJ3nQJiutT-sgp0dyHR2HIL6FYEhD3t2CNuoHJoSIOia5ffo_rjfxW_pk8co0i7UMTYANNGxsRNJLQTu_Alw==")
//                //.header("Authorization","Token 0371a29044432d36cc2508b7ce51e70f466c7d95")
//                .header("Content-Type", "application/json")
//                .body("{\"contacts\": [\"8618102810628\"],\"sender_id\": \"EC\",\"message\": \"say hello everybody.\",\"priority_route\": False,\"campaign_name\": \"mytest\"}")
//                .asString();
//        System.out.println("response is ------------------------>"+response.getBody());;
    }

    public void postReq(List<String> phonenums, String message){
        HttpClient client = HttpClientFactory.get(Request.Util.OkHttp);
        String sendUrl = "https://whispersms.xyz/whisper/send_message/";
        //String sendUrl = "https://whispersms.xyz/api/send_message/";
        Map<String, Object> param = new HashMap<>();
        param.put("contacts",phonenums);
        param.put("message",message);
        param.put("sender_id","EC");
        param.put("priority_route","False");
        param.put("campaign_name","EClogistics");

        Map<String, String> header = new HashMap<>();
        //header.put("Accept","application/json,text/plain,*/*");
        header.put("Content-Type", "application/json");
        header.put("Authorization","Token 0371a29044432d36cc2508b7ce51e70f466c7d95");
        //header.put("Authorization", "Api_key gAAAAABl5ZDpoKnKVaK0scmWo7GQeKDA1sn3OZBeMXUz211vZv5QqSEtr7_LD5ISTqSD0PnWLRWavYmJ3nQJiutT-sgp0dyHR2HIL6FYEhD3t2CNuoHJoSIOia5ffo_rjfxW_pk8co0i7UMTYANNGxsRNJLQTu_Alw==");

        Request req = Request.create(sendUrl,Request.Method.POST,param);
        req.setParamFormat(Request.ParamFormat.JSON);
        try {
            Response res = client.execute(req,Request.Option.create(0,0,header));
            log.info("response code ---------------------------->"+res.getCode());
            log.info("response content is --------------------》"+res.getBody());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args){
        WhisperClientHttp test = new WhisperClientHttp();
        //test.testPost();
        List<String>  phonenums = new ArrayList<>();
        phonenums.add("8618102810628");
        phonenums.add("2348140352000");
        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 :+8615920356527";
        test.postReq(phonenums,message);
        //test.testPost();
    }
}
