配置支付宝支付沙箱

tech2023-01-12  183

配置支付宝支付沙箱

1.准备工具

支付宝开放平台开发助手

客户端调试 手机安装

2.配置沙箱环境

打开支付宝开放平台开发助手 生成密钥

到支付宝开放平台官网:https://openhome.alipay.com/platform/appDaily.htm?tab=info 进行配置: 点击设置把密钥粘贴过来

3.创建maven项目

到maven官网下载jar包:https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java/4.10.111.ALL

SDK生成

去支付宝官网找开发工具,JAVA服务端 SDK 生成 APP支付订单信息示例 https://opendocs.alipay.com/open/54/106370

创建Controller

放入我们刚复制的示例,自定义修改

@RestController @RequestMapping("/pay/ali") public class AliPayController { /** * APP_ID 应用id */ public final static String APP_ID ="2016093000630181"; /** * 应用私钥 */ public final static String APP_PRIVATE_KEY = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCTO5ERumMOQlwy2+2hrSUgqFd+PsQ5Au+sK7+xNrB6fmR2oSWSn+X8EEjQBWq21RWV1ekABWSsG2BtOWlnWxT77tfyXLOzejR3vujFhwLPshzA9lfR2R5fH/F3l0MGmWvb3GGYqp2q2SR7jXUtOU5dEEGHUYRd9zoy9CPEM2Iu1xWA5ks51C5XH2AJV62ZDCc82sAJt7xfrDLCZbwKGp0a4b6ZgA1OoZDn7Jzp160fFA81EbkfrKK+qOoyMV9dbHSotHHQfD3+49o1coz3vpPY9r/kD6FhZ3ZdU1SfYccaEpyMAbdfR/RAtHlRiA9JUgXXFiExavKUEwdEGizwug45AgMBAAECggEAftF2GXEUVXnvdJdfTj2Xl1OpWUKzPfA7hW+BhCF5TWmFG3GerXcxYDaeoR+pVaahGxjPw4bhuiUyn6IuGiqoHoESXN5gox2GCAbW9R1f3IqsncESz9xWftVC5iHSR+LqtsxS/G8ps7mp5QppffS4fQy9hNNAUrfa13zXOe6QiYq/BHiBzJKT4Bp4P5iQMM4/J/Y4fPOHTHEo4iZX+a2WC2ZBMbAXZWfMmIKenqZVDuf7GO8/TpHMpkI9pEePU7njSqRX2+zixcVJ/M8EgSj0JCFZUUCKDz78Nuu2UvdTrLfFTYTIrr4nhVdsduDpJ0LKSJEcvaxku1AhgRgWBgfj6QKBgQDzugV2tnWG495gQyipqPXIYd2JVIdWfAgUfNdDD8bd/FZ/grATQo4R4zDdgXS5a2c0AFzJU7MMkWo4DTKpjU6aZIdY8PdgnI3SefKJzw3ndBGPou5RbVFVkrehahU4u1LVKldmo/pvlMCqpp00UBkO2Tzl4v6lLQsRKXvJCDJvjwKBgQCapZpIW+nk8QjkArsqY2j9NQeRz3JRQ6UJkW4sf+4JgbtXgXgu/arpCTevCi50zqv8TE4nmJj8YtE0H7qbBgOSgJV2i+0/eRCsV8oNu9WzQVM8qyGtoQ4fKxhMNN2CcWGh5gXk2wRG6qFz69MxEJ+RAK5ev4w1bDu89SS4d5dBtwKBgDqEZEFvZ2JenYqxNTce6PwWezE4yVG7b9kzbB+ezxmHN2FgCFRne2LSEG5uYY8POXUjzSNNZETVORKCILLSyZeKIXD6UfqxO9/YBaKOwwDaPkklTmDghVGta0dnB/daCnZBt0BeiId3yJZwcHgZ7xpAkD2FtawE145kTmMjA7EDAoGAEqpGMtGVK2LENfD2cilJdLY/0aN+IrzNYJhC+e/+5PrZh7hCrzlCtZm9NM0/yi1fqLX1AOZ0IJI0udvSg/930ujeIU7GNdEA6Cw4YOv44QfTahEloXU85Roodpoy2hmhNQ80Suj8XSrYjcs61EMzXyb75MetvozvsODNq84TXYUCgYB11cFAnLXztA2wKjRSsPP8Hm1vDLmq4CoM2qyqeDSdVCeRqQJ4VSwtsFsGRPXfrrx4CbTKDRiV04hJTVYtnpX67bo34GIXxW1RtLYeCk1lWBI7u3D398qMGcpbo3FzwJ+v8pD3uzTTnk88Xx2qUeghRoLvQd/KP0dcfpZLllBOFA=="; /** * 编码 */ public final static String CHARSET ="UTF-8"; /** * 支付宝公钥 */ public final static String ALIPAY_PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjeZA25b4mJZpWWXHR0joM8eOSm1DuBDKKgq5ZYDkxKUPhLuXfK588EcFaSGlW9yzpvNkxBbq3QEzqx5K3zYaVHjzh0y+8vlfCcFINMpcYgy3q8NsQHgipO994TqIUwukac8GzezVAT7avtwBeWMNGJDnpQAJNkOD6se2sMu2IXFa7GkfRxhJCMNi/e/d16j0D/YfT2F1c1hRzH1Ey0I3Rkx1WxZTPYH+lCSVaIkxVtolYIpoktE70ZVcD1ERy5eipWCT4sdl/UMifgTnj+PyL+R6lzMUVPKQ+xk5G5PoJUiRSAOkqcaB+KTaerL0h0VzOXKqQ2O/3ppdrTn4X+mAgQIDAQAB"; /** * (沙箱)网关 */ public final static String GETEWAY_URL ="https://openapi.alipaydev.com/gateway.do"; /** * 格式化 */ public final static String FORMAT ="json"; /** * 签名类型 */ public final static String SIGN_TYPE ="RSA2"; /** * 获取订单信息 */ @GetMapping("/getOrderInfo") public String getOrderInfo(String orderId){ //实例化客户端 AlipayClient alipayClient = new DefaultAlipayClient(GETEWAY_URL, APP_ID, APP_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_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("87878978976"); //交易号 model.setTimeoutExpress("30m"); model.setTotalAmount("6.66"); model.setProductCode("QUICK_MSECURITY_PAY"); //将自己想要传递到异步接口的数据,set进去 pass_back_params model.setPassbackParams(orderId); request.setBizModel(model); request.setNotifyUrl("http://3j383810f3.zicp.vip/pay/ali/notif_url"); try { //这里和普通的接口调用不同,使用的是sdkExecute AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request); System.out.println("response.getBody():"+response.getBody());//就是orderString 可以直接给客户端请求,无需再做处理。 return response.getBody(); } catch ( AlipayApiException e) { e.printStackTrace(); return null; } }

1 APP_ID

在我们沙箱环境中查看

2 APP_PRIVATE_KEY及商户私钥

3.CHARSET 编码一般都是UTF-8

4.ALIPAY_PUBLIC_KEY支付宝公钥

5.FORMAT格式json 6.GATEWAY_URL沙箱网关

7.sign_type参数类型RSA2

然后我们开始测试:

public static void main(String[] args) { AliPayController aliPayController = new AliPayController(); aliPayController.getOrderInfo(null); }

运行后控制台输出一串字符:

复制生成的一串字符到客户端测试APP测试 输入付款密码 然后我们就成功了。

最新回复(0)