| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.product.text.message.util; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.net.URLEncoder; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.product.core.config.Global; |
| | | import com.product.core.exception.BaseException; |
| | | import com.product.core.message.ISMSService; |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.util.config.ErrorCode; |
| | | |
| | | /** |
| | | * å®ç°çä¿¡åé |
| | | * æåæ´ï¼å¦åä¸ä¸ªæ°ç±»ï¼å®ç°æ¥å£ï¼å¹¶å»æèç±»çå®ç°ç±»ï¼å³å¯ |
| | | * @version å建æ¶é´ï¼2017å¹´3æ27æ¥ ä¸å2:36:08 |
| | | * |
| | | */ |
| | | @Service |
| | | public class LinKaiSMSUtil implements ISMSService { |
| | | private static String Url = "http://106.ihuyi.cn/webservice/sms.php?method=Submit"; |
| | | private static String CorpID="CDJS003057";//è´¦æ·å |
| | | private static String Pwd="zm0513@";//å¯ç |
| | | private static String Signature="ãæé½é¾æ¬£è½¯ä»¶æéå
¬å¸ã";//ç¾å 德润ç¾å®¶ ä¼ä¸ç®¡çå¹³å° æé½é¾æ¬£ç§æ |
| | | static Map<String,String> error=new HashMap<>(); |
| | | static{ |
| | | error.put("-1","è´¦å·æªæ³¨å"); |
| | | error.put("-2","å
¶ä»é误:"); |
| | | error.put("-3","å¸å·æå¯ç é误"); |
| | | error.put("-5","ä½é¢ä¸è¶³ï¼è¯·å
å¼"); |
| | | error.put("-6","宿¶åéæ¶é´ä¸æ¯ææçæ¶é´æ ¼å¼"); |
| | | error.put("-7","æäº¤ä¿¡æ¯æ«å°¾æªå ç¾åï¼è¯·æ·»å 䏿çä¼ä¸ç¾åãã"); |
| | | error.put("-8","åéå
容éå¨1å°300åä¹é´"); |
| | | error.put("-9","åéå·ç 为空"); |
| | | error.put("-10","宿¶æ¶é´ä¸è½å°äºç³»ç»å½åæ¶é´"); |
| | | error.put("-11","å±è½ææºå·ç "); |
| | | error.put("-100","IPé»åå"); |
| | | error.put("-101","è°ç¨æ¥å£é¢çè¿å¿«(大äº30sè°ç¨ä¸æ¬¡)"); |
| | | error.put("-102","è´¦å·é»åå"); |
| | | error.put("-103","IPæªå¯¼ç½"); |
| | | } |
| | | /**æå±-ç¼éçä¿¡æ¥å£*/ |
| | | /** |
| | | * |
| | | */ |
| | | @Override |
| | | public int sendSMS(String mobile,String content,String send_time) throws BaseException{ |
| | | URL url = null; |
| | | content+=Signature; |
| | | try { |
| | | String send_content=URLEncoder.encode(content.replaceAll("<br/>", " "), "GBK");//åéå
容 |
| | | url = new URL("https://sdk2.028lk.com/sdk2/BatchSend2.aspx?CorpID="+CorpID+"&Pwd="+Pwd+"&Mobile="+mobile+"&Content="+send_content+"&Cell=&SendTime="+send_time); |
| | | // url = new URL("https://sdk2.028lk.com/sdk2/SelSum.aspx?CorpID="+CorpID+"&Pwd="+Pwd); // æ¥è¯¢çä¿¡å©ä½æ¡æ° |
| | | BufferedReader in = null; |
| | | int inputLine = 0; |
| | | in = new BufferedReader(new InputStreamReader(url.openStream())); |
| | | inputLine = new Integer(in.readLine()).intValue(); |
| | | SpringMVCContextHolder.getSystemLogger().info("çä¿¡åéï¼"+content+",è¿åç»æï¼"+inputLine); |
| | | if(inputLine<0) { |
| | | throw new BaseException(""+inputLine,""+error.get(""+inputLine)); |
| | | } |
| | | return inputLine; |
| | | }catch(Exception e) { |
| | | e.printStackTrace(); |
| | | throw new BaseException(ErrorCode.MESSAGE_SMS_SEND_FAIL); |
| | | } |
| | | |
| | | } |
| | | // /**æå±-ç¼éçä¿¡æ¥å£*/ |
| | | // @Override |
| | | // public int sendSMS(String Mobile,String Content,String send_time)throws BaseException { |
| | | // URL url = null; |
| | | // Content+=Signature; |
| | | // String send_content= null;//åéå
容 |
| | | // try { |
| | | // send_content = URLEncoder.encode(Content.replaceAll("<br/>", " "), "GBK"); |
| | | // url = new URL("https://sdk2.028lk.com/sdk2/BatchSend2.aspx?CorpID="+CorpID+"&Pwd="+Pwd+"&Mobile="+Mobile+"&Content="+send_content+"&Cell=&SendTime="+send_time); |
| | | // } catch (UnsupportedEncodingException | MalformedURLException e) { |
| | | // throw new BaseException("public int sendSMS(String Mobile,String Content,String send_time)throws BaseException",e.getMessage()); |
| | | // } |
| | | // System.out.println("urlï¼"+url.to); |
| | | //// url = new URL("https://sdk2.028lk.com/sdk2/SelSum.aspx?CorpID="+CorpID+"&Pwd="+Pwd); // æ¥è¯¢çä¿¡å©ä½æ¡æ° |
| | | // BufferedReader in = null; |
| | | // int inputLine = 0; |
| | | // try { |
| | | // System.out.println("å¼å§åéçä¿¡ææºå·ç 为 ï¼"+Mobile); |
| | | // in = new BufferedReader(new InputStreamReader(url.openStream())); |
| | | // inputLine = new Integer(in.readLine()).intValue(); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // System.out.println("ç½ç»å¼å¸¸,åéç信失败ï¼"); |
| | | // throw new BaseException("ç½ç»å¼å¸¸,åéç信失败ï¼-2",e.getMessage()); |
| | | // } |
| | | // System.out.println("ç»æåéçä¿¡è¿åå¼ï¼ "+inputLine); |
| | | // return inputLine; |
| | | // } |
| | | |
| | | public String SendSMS(String phoneNum) { |
| | | int mobile_code = (int)((Math.random()*9+1)*100000); |
| | | String content = new String("æ¨çéªè¯ç æ¯ï¼" + mobile_code + "ï¼è¯·ä¸è¦æéªè¯ç æ³é²ç»å
¶ä»äººã"); |
| | | int result; |
| | | try { |
| | | result = sendSMS(phoneNum, content, ""); |
| | | if (result > 0) { |
| | | return mobile_code + ""; |
| | | } |
| | | } catch (Exception e) { |
| | | return "-2"; |
| | | } |
| | | return result + ""; |
| | | } |
| | | public static void main(String[] args) { |
| | | LinKaiSMSUtil smsUtil = new LinKaiSMSUtil(); |
| | | System.out.println(smsUtil.SendSMS("18030850875")); |
| | | |
| | | } |
| | | } |