准备好
- 支付宝开放平台开发助手
- 支付宝开放平台 申请自己的沙箱环境
- 花生壳 内网穿透工具 6元 98年 实名认证
- 客户端调试工具 手机安装
去官网登录点击研发服务
在支付宝开放平台开发助手获取密钥并输入
java代码:id 密钥,公钥,url我都改了 大家根据自己的填写就可以了
public class AliPayController {
/**
* appID
*/
public final static String APP_ID="20210001186681";
/**
* 应用密钥
*/
public final static String APP_PRIVATE_KEY="MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCFDZl1fml/LfBDIunLp469QA3wBIHF2CRE3smYGoGeqbHtnwqweFqsbgQtTK4Cns3W6FM+iM/pYgIUt+NMGhZ/UGevw/x4psP1UjFc8VqIw5MU0zaEsgR6IAMRuIwWSIH4wCNRhKXTGdT285PaQn1iPoaJQNsFLpmpobt49fEsHXWHyPc9E16dwy0W4icGmveZCcJB5BHRAg9AqokvUVed3YMWi7F+HMqV4hHzaMuLrgMDGkY7++YwR2hxb8TevfBCh4ESyktijK91n+ihkTmrvU2L/oeMfK51D4iB1YOR18zSpwP3adl0NeJWNP4Rv0cTsxNoVJCJr3oyDrOzzg4zAgMBAAECggEAXYHDOamPpsu4MNaWjIPDcwlTQj1InqxaQPR5pSXrtn/4BdFiB8dtogTndpaPLFRCwSghaK9pvtEcOUdKvK8Q5ISzefk4s+oviXcsLe+I+tjHwzj09ajOMK3Sul+CRB7NCO6vY5jfmU5sNunUHO3hhGwAzPEBe9DWOTrqsAXYanF901Sb7ZgGBGdUEYDPLCbrwWmrqsKorIFNvKxavhQS0jQ8FFn4zEW797/7cGvHMIQLB1hE/wcPaktclmZVvaOlMOF1Wm+pCZfanPOKLkGUzd1ywCwyd7KgQa7o4z/vLHSPZl4aYMOIU5T98DaQ5pCBJpYT0FjaF2lBCI6l28mRwQKBgQDDdlQ7resLMh9odtKCr6fTw5/Z3VfHVTKHWBqiSGm4+Sn5+OjzEUYoFCY7gUSXTejGuzEuNdvtHESA0H1Cc+5ynfIbQIuR678gDtwP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DAxpGO/vmMEdocW/E3r3wQoeBEspLYoyvdZ/ooZE5q71Ni/B";
/**
*
*/
public final static String serverURL="https://openapi.alipay.com/gateway.do";
/**
*
*/
public final static String FORMAT="json";
/**
*
*/
public final static String SING_TYPE="RSA2";
public void getOrderInfo(){
//实例化客户端
AlipayClient alipayClient = new DefaultAlipayClient(serverURL, APP_ID, APP_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY,SING_TYPE );
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
model.setBody("我是测试数据");
model.setSubject("App支付测试Java");
model.setOutTradeNo("158131415728");
model.setTimeoutExpress("30m");
model.setTotalAmount("0.01");
model.setProductCode("QUICK_MSECURITY_PAY");
request.setBizModel(model);
request.setNotifyUrl("http://3wa3852747.qicp.vip");
try {
//这里和普通的接口调用不同,使用的是sdkExecute
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
System.out.println(response.getBody());//就是orderString 可以直接给客户端请求,无需再做处理。
} catch (AlipayApiException e) {
e.printStackTrace();
}
}
@PostMapping("/notify")
public String notify_url(HttpServletRequest request) {
Map<String, String> params = new HashMap<String, String>();
Map requestParams = request.getParameterMap();
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
String name = (String) iter.next();
String[] values = (String[]) requestParams.get(name);
String valueStr = "";
for (int i = 0; i < values.length; i++) {
valueStr = (i == values.length - 1) ? valueStr + values[i]
: valueStr + values[i] + ",";
}
//乱码解决,这段代码在出现乱码时使用。
//valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
params.put(name, valueStr);
}
//切记alipaypublickey是支付宝的公钥,请去open.alipay.com对应应用下查看。
//boolean AlipaySignature.rsaCheckV1(Map<String, String> params, String publicKey, String charset, String sign_type)
try {
boolean flag = AlipaySignature.rsaCheckV1(params, ALIPAY_PUBLIC_KEY, CHARSET, SING_TYPE);
if (!flag) {
System.out.println("success");
return "success";
} else {
System.out.println("flag");
return "flag";
}
} catch (AlipayApiException e) {
e.printStackTrace();
return "flag";
}
}
public static void main(String[] args) {
AliPayController apc=new AliPayController();
apc.getOrderInfo();
}
}
根据自己的修改就可以了,然后复制下面那一行 去手机端的客户端调试工具就可以了。