阿里云大 最新短信接口

public static boolean getPhoneCode(String phoneNum, String checkCode) {
		 DefaultProfile profile = DefaultProfile.getProfile("default",CommonProperties.accessKeyId , CommonProperties.accessSecret);
	        IAcsClient client = new DefaultAcsClient(profile);

	        CommonRequest request = new CommonRequest();
	        request.setMethod(MethodType.POST);
	        request.setDomain("dysmsapi.aliyuncs.com");
	        request.setVersion("2017-05-25");
	        request.setAction("SendBatchSms");
	       // request.putQueryParameter("RegionId", "聊城");
	        request.putQueryParameter("PhoneNumberJson", "[\""+phoneNum+"\"]");
	        request.putQueryParameter("SignNameJson", "[\""+CommonProperties.SignNameJson+"\"]");
	        request.putQueryParameter("TemplateCode", CommonProperties.TemplateCode);
	        request.putQueryParameter("TemplateParamJson", "[{\"code\":\""+checkCode+"\"}]");
	        boolean flag = false;
	        try {
	            CommonResponse response = client.getCommonResponse(request);
	            System.out.println(response.getData());
	            JSONObject jsonObj = new JSONObject(response.getData().toString());
				String codeString = (String) jsonObj.get("Code");
				if(codeString.equals("OK")) {
					flag = true;
				}
	        } catch (ServerException e) {
	            e.printStackTrace();
	        } catch (ClientException e) {
	            e.printStackTrace();
	        } catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	       return flag;
	}

具体问题看阿里云文档 主要是格式,之前都是报格式错误

你可能感兴趣的:(阿里云大 最新短信接口)