阿里短信验证码接口和支付宝沙箱支付接口
一、阿里短信验证码接口
1. 申请阿里AccessKey,填写AccessKey ID和AccessKeySecret
2. 申请短信的签名名称和模板
Java的API接口如下,其中模板可根据自己需要进行修改
/**发送短信*/
public Integer SendMsg(String PhoneNumbers, String TemplateParam,Integer type) {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "AccessKey ID", "AccessKeySecret");
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
//request.setProtocol(ProtocolType.HTTPS);
request.setMethod(MethodType.POST);
request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25");
request.setAction("SendSms");
request.putQueryParameter("RegionId", "cn-hangzhou");
request.putQueryParameter("PhoneNumbers", PhoneNumbers);
request.putQueryParameter("SignName", "签名名称");
if(type == 0){//发送注册验证码
request.putQueryParameter("TemplateCode", "模板");
}else if(type == 1){//发送重置密码验证码
request.putQueryParameter("TemplateCode", "模板");
}else if (type == 2){//发送更换手机号验证码
request.putQueryParameter("TemplateCode", "模板");
}
request.putQueryParameter("TemplateParam", "{\"code\":\""+TemplateParam+"\"}");
CommonResponse response=null;
try {
response = client.getCommonResponse(request);
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
JSONObject result = new JSONObject(response.getData());
if(result.getString("Code").equals("OK")){
return 1;
}
if(result.getString("Code").equals("isv.MOBILE_NUMBER_ILLEGAL")){
return 2;//非法手机号
}
return 0;
}
二、支付宝沙箱支付接口
1. 在支付宝开放平台中获取APPID,先通过支付宝开放平台开发助手生成应用公钥,通过应用公钥在开放平台中生成支付宝公钥,使用应用私钥和支付宝公钥
生成应用公钥及私钥
生成支付宝公钥
2. Java的API接口如下,填写APPID及应用私钥、支付宝公钥,详情API请查看支付宝开放平台
public class AlipayConfig {
// 应用ID,您的APPID,收款账号既是您的APPID对应支付宝账号
public static String app_id = "填入APPID";
// 应用私钥,您的PKCS8格式RSA2私钥
public static String merchant_private_key = "填入生成的应用私钥";
// 支付宝公钥
public static String alipay_public_key = "填入生成的支付宝公钥";
public static String notify_url = "http://localhost/alipay/alipayReturnNotice";
public static String return_url = "http://localhost/alipay/alipayReturnNotice";
public static String sign_type = "RSA2";
public static String charset = "utf-8";
public static String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";//注意:沙箱测试环境,正式环境为:https://openapi.alipay.com/gateway.do
}