package com.doumee.service.business.third; 
 | 
  
 | 
import cn.emay.sdk.client.SmsSDKClient; 
 | 
import cn.emay.sdk.core.dto.sms.common.CustomSmsIdAndMobile; 
 | 
import cn.emay.sdk.core.dto.sms.common.CustomSmsIdAndMobileAndContent; 
 | 
import cn.emay.sdk.core.dto.sms.common.PersonalityParams; 
 | 
import cn.emay.sdk.core.dto.sms.common.ResultModel; 
 | 
import cn.emay.sdk.core.dto.sms.request.*; 
 | 
import cn.emay.sdk.core.dto.sms.response.*; 
 | 
import cn.emay.sdk.util.exception.SDKParamsException; 
 | 
import com.alibaba.fastjson.JSONObject; 
 | 
import com.doumee.biz.system.SystemDictDataBiz; 
 | 
import com.doumee.core.utils.Constants; 
 | 
import com.doumee.dao.business.model.InterfaceLog; 
 | 
import com.doumee.service.business.InterfaceLogService; 
 | 
import org.springframework.beans.factory.annotation.Autowired; 
 | 
import org.springframework.stereotype.Service; 
 | 
  
 | 
import javax.annotation.PostConstruct; 
 | 
import java.io.IOException; 
 | 
import java.util.Date; 
 | 
  
 | 
@Service 
 | 
public class EmayService { 
 | 
    private static SmsSDKClient client ; 
 | 
  
 | 
    public SmsSDKClient getClient() { 
 | 
        return client; 
 | 
    } 
 | 
  
 | 
    public void setClient(SmsSDKClient client) { 
 | 
        this.client = client; 
 | 
    } 
 | 
    @Autowired 
 | 
    private InterfaceLogService interfaceLogService  ; 
 | 
    @Autowired 
 | 
    private SystemDictDataBiz  systemDictDataBiz; 
 | 
    private   void saveInterfaceLog(String path,String name,String req ,String res) { 
 | 
        if(interfaceLogService !=null){ 
 | 
            InterfaceLog hkMonitoryLogDO=new InterfaceLog(); 
 | 
            hkMonitoryLogDO.setType(0); 
 | 
            hkMonitoryLogDO.setCreateDate(new Date()); 
 | 
            hkMonitoryLogDO.setIsdeleted(0); 
 | 
            hkMonitoryLogDO.setRequest(req); 
 | 
            hkMonitoryLogDO.setRepose(res); 
 | 
            hkMonitoryLogDO.setName(name); 
 | 
            hkMonitoryLogDO.setUrl(path); 
 | 
            interfaceLogService.create(hkMonitoryLogDO); 
 | 
        } 
 | 
    } 
 | 
    private  static String  ip; 
 | 
    private static int port; 
 | 
    private static String appSecret; 
 | 
    private static String appKey; 
 | 
    @PostConstruct//启动初始化 
 | 
    public int initClient(){ 
 | 
        ip = systemDictDataBiz.queryByCode(Constants.SMS,Constants.SMS_IP).getCode(); 
 | 
        port = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.SMS,Constants.SMS_PORT).getCode()); 
 | 
        appKey = systemDictDataBiz.queryByCode(Constants.SMS,Constants.SMS_APPKEY).getCode(); 
 | 
        appSecret = systemDictDataBiz.queryByCode(Constants.SMS,Constants.SMS_APPSECRET).getCode(); 
 | 
        return 0; 
 | 
    } 
 | 
  
 | 
    public   boolean sendSingleSms(String mobile,String content) throws SDKParamsException { 
 | 
        try { 
 | 
            client = new SmsSDKClient(ip,port,appKey,appSecret); 
 | 
        } catch (SDKParamsException e) { 
 | 
            throw new RuntimeException(e); 
 | 
        } 
 | 
        if(client == null){ 
 | 
            return false; 
 | 
        } 
 | 
        String customSmsId = "1"; 
 | 
        String extendedCode = "01"; 
 | 
  
 | 
        SmsSingleRequest request = new SmsSingleRequest(mobile, content, customSmsId, extendedCode, ""); 
 | 
        ResultModel<SmsResponse> result = client.sendSingleSms(request); 
 | 
        saveInterfaceLog(ip+"/"+port,"【短信】发送", JSONObject.toJSONString(result),JSONObject.toJSONString(result)); 
 | 
        if (result.getCode().equals("SUCCESS")) { 
 | 
            System.out.println("请求成功"); 
 | 
            SmsResponse response = result.getResult(); 
 | 
            System.out.println("sendSingleSms:" + response.toString()); 
 | 
            return  true; 
 | 
        } else { 
 | 
            System.out.println("请求失败"); 
 | 
            return false; 
 | 
        } 
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |