package com.sino.java.thirdparty;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import com.sino.java.utility.Http;
public class VcomUtil {
/**
* 将登录密码采用32位大写MD5方式加密
* @return
* @throws Exception
*/
public static String Md5Pwd(){
StringBuffer buf = new StringBuffer();
MessageDigest md;
String pwd = null;
try {
md = MessageDigest.getInstance("MD5");
md.update("xntx123".getBytes());
byte b[] = md.digest();
int i;
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0) {
i += 256;
}
if (i < 16) {
buf.append("0");
}
buf.append(Integer.toHexString(i));
}
pwd = buf.toString().toUpperCase();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return pwd;
}
/**
* 拼接短信接口XML
* @param OpKind
* @param InterFaceID
* @param SerType
* @param ETime
* @param RecivePhoneNum
* @param Content
* @param SearchID
* @param num
* @return
* @throws Exception
*/
public static String sendNumAndContent(String OpKind,String InterFaceID,
String SerType,String ETime,String[] RecivePhoneNum,String[] Content,String[] SearchID,int num) throws Exception{
StringBuffer buffer = new StringBuffer();
buffer.append("<Group Login_Name='xntx' Login_Pwd='"+Md5Pwd()+"' OpKind='"+OpKind+"' InterFaceID='"+InterFaceID+"'");
if(SerType != null && !SerType.equals("")){
buffer.append("SerType='"+SerType+"'");
}
buffer.append(">");
if(ETime != null && !ETime.equals("")){
buffer.append("<E_Time>"+ETime+"</E_Time>");
}else{
buffer.append("<E_Time></E_Time>");
}
if(OpKind != "0" && !OpKind.equals("0")){
buffer.append("<Mobile>");
for(int i=0;i<num;i++){
buffer.append(RecivePhoneNum[i]);
if(i != num-1){
buffer.append(",");
}
}
buffer.append("</Mobile>");
buffer.append("<Content><![CDATA["+Content[0]+"]]></Content>");
buffer.append("<ClientID>"+SearchID[0]+"</ClientID>");
}
else {
buffer.append("<Item>");
for(int i=0;i<num;i++){
buffer.append("<Task>");
buffer.append("<Recive_Phone_Number>"+RecivePhoneNum[i]+"</Recive_Phone_Number>");
buffer.append("<Content><![CDATA["+Content[i]+"]]></Content>");
buffer.append("<Search_ID>"+SearchID[i]+"</Search_ID>");
buffer.append("</Task>");
}
buffer.append("</Item>");
}
buffer.append("</Group>");
// System.out.println("--------------------------"+buffer);
return buffer.toString();
}
/**
*判断传入的参数的正确性
* @param OpKind
* @param InterFaceID
* @param SerType
* @param ETime
* @param RecivePhoneNum
* @param Content
* @param SearchID
* @param num
* @return
*/
public static boolean verificateSend(String OpKind,String InterFaceID,
String SerType,String ETime,String[] RecivePhoneNum,String[] Content,String[] SearchID,int num){
boolean flag=false;
String str=null;
if(SerType.length() > 5){
str="SerType不能超过5长度的字符串";
System.out.println(str);
return flag;
}
if(OpKind == null || OpKind.equals("")){
str="业务类型不能为空,默认为0";
System.out.println(str);
return flag;
}
else if(OpKind.equals("51")){
if(RecivePhoneNum.length > 50){
str= "手机号的个数不能超过50个";
System.out.println(str);
return flag;
}
}
else if(OpKind.equals("0")){
if(RecivePhoneNum.length > 10){
str= "手机号的个数不能超过10个";
System.out.println(str);
return flag;
}
}
else{
str= "OpKind 值无效";
System.out.println(str);
return flag;
}
for(int i=0;i<num;i++){
if(SearchID[i].length() > 40){
System.out.println(str);
str="流水号的长度不能超过40";
}
}
return true;
}
/**
* 调用短信接口
* @param OpKind
* @param InterFaceID
* @param SerType
* @param ETime
* @param RecivePhoneNum
* @param Content
* @param SearchID
* @param num
* @return
* @throws Exception
*/
public static String send(String OpKind,String InterFaceID,
String SerType,String ETime,String[] RecivePhoneNum,String[] Content,String[] SearchID,int num) throws Exception{
// String html="";
// System.out.println(verificateSend(OpKind, InterFaceID, SerType, ETime, RecivePhoneNum, Content, SearchID, num));
if(verificateSend(OpKind, InterFaceID, SerType, ETime, RecivePhoneNum, Content, SearchID, num)){
return Http.Send("POST","http://slapi.vcomcn.com/Opration.aspx",sendNumAndContent(OpKind, InterFaceID, SerType, ETime, RecivePhoneNum, Content, SearchID, num),"GB2312");
}
return "exception";
}
}
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import com.sino.java.utility.Http;
public class VcomUtil {
/**
* 将登录密码采用32位大写MD5方式加密
* @return
* @throws Exception
*/
public static String Md5Pwd(){
StringBuffer buf = new StringBuffer();
MessageDigest md;
String pwd = null;
try {
md = MessageDigest.getInstance("MD5");
md.update("xntx123".getBytes());
byte b[] = md.digest();
int i;
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0) {
i += 256;
}
if (i < 16) {
buf.append("0");
}
buf.append(Integer.toHexString(i));
}
pwd = buf.toString().toUpperCase();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return pwd;
}
/**
* 拼接短信接口XML
* @param OpKind
* @param InterFaceID
* @param SerType
* @param ETime
* @param RecivePhoneNum
* @param Content
* @param SearchID
* @param num
* @return
* @throws Exception
*/
public static String sendNumAndContent(String OpKind,String InterFaceID,
String SerType,String ETime,String[] RecivePhoneNum,String[] Content,String[] SearchID,int num) throws Exception{
StringBuffer buffer = new StringBuffer();
buffer.append("<Group Login_Name='xntx' Login_Pwd='"+Md5Pwd()+"' OpKind='"+OpKind+"' InterFaceID='"+InterFaceID+"'");
if(SerType != null && !SerType.equals("")){
buffer.append("SerType='"+SerType+"'");
}
buffer.append(">");
if(ETime != null && !ETime.equals("")){
buffer.append("<E_Time>"+ETime+"</E_Time>");
}else{
buffer.append("<E_Time></E_Time>");
}
if(OpKind != "0" && !OpKind.equals("0")){
buffer.append("<Mobile>");
for(int i=0;i<num;i++){
buffer.append(RecivePhoneNum[i]);
if(i != num-1){
buffer.append(",");
}
}
buffer.append("</Mobile>");
buffer.append("<Content><![CDATA["+Content[0]+"]]></Content>");
buffer.append("<ClientID>"+SearchID[0]+"</ClientID>");
}
else {
buffer.append("<Item>");
for(int i=0;i<num;i++){
buffer.append("<Task>");
buffer.append("<Recive_Phone_Number>"+RecivePhoneNum[i]+"</Recive_Phone_Number>");
buffer.append("<Content><![CDATA["+Content[i]+"]]></Content>");
buffer.append("<Search_ID>"+SearchID[i]+"</Search_ID>");
buffer.append("</Task>");
}
buffer.append("</Item>");
}
buffer.append("</Group>");
// System.out.println("--------------------------"+buffer);
return buffer.toString();
}
/**
*判断传入的参数的正确性
* @param OpKind
* @param InterFaceID
* @param SerType
* @param ETime
* @param RecivePhoneNum
* @param Content
* @param SearchID
* @param num
* @return
*/
public static boolean verificateSend(String OpKind,String InterFaceID,
String SerType,String ETime,String[] RecivePhoneNum,String[] Content,String[] SearchID,int num){
boolean flag=false;
String str=null;
if(SerType.length() > 5){
str="SerType不能超过5长度的字符串";
System.out.println(str);
return flag;
}
if(OpKind == null || OpKind.equals("")){
str="业务类型不能为空,默认为0";
System.out.println(str);
return flag;
}
else if(OpKind.equals("51")){
if(RecivePhoneNum.length > 50){
str= "手机号的个数不能超过50个";
System.out.println(str);
return flag;
}
}
else if(OpKind.equals("0")){
if(RecivePhoneNum.length > 10){
str= "手机号的个数不能超过10个";
System.out.println(str);
return flag;
}
}
else{
str= "OpKind 值无效";
System.out.println(str);
return flag;
}
for(int i=0;i<num;i++){
if(SearchID[i].length() > 40){
System.out.println(str);
str="流水号的长度不能超过40";
}
}
return true;
}
/**
* 调用短信接口
* @param OpKind
* @param InterFaceID
* @param SerType
* @param ETime
* @param RecivePhoneNum
* @param Content
* @param SearchID
* @param num
* @return
* @throws Exception
*/
public static String send(String OpKind,String InterFaceID,
String SerType,String ETime,String[] RecivePhoneNum,String[] Content,String[] SearchID,int num) throws Exception{
// String html="";
// System.out.println(verificateSend(OpKind, InterFaceID, SerType, ETime, RecivePhoneNum, Content, SearchID, num));
if(verificateSend(OpKind, InterFaceID, SerType, ETime, RecivePhoneNum, Content, SearchID, num)){
return Http.Send("POST","http://slapi.vcomcn.com/Opration.aspx",sendNumAndContent(OpKind, InterFaceID, SerType, ETime, RecivePhoneNum, Content, SearchID, num),"GB2312");
}
return "exception";
}
}