当前位置:网站首页>Alibaba cloud Alipay sandbox payment
Alibaba cloud Alipay sandbox payment
2022-07-03 05:51:00 【SSID-cc-r】
Alibaba cloud Alipay sandbox payment
The project file is maven project
First step pom.xml introduce jar package
<!-- Sandbox payment dependency -->
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.20.0.ALL</version>
</dependency>
Create a AlipayConfig class
package com.alipay.config;
import java.io.FileWriter;
import java.io.IOException;
/* *
* Class name :AlipayConfig
* function : Basic configuration class
* detailed : Set up account information and return path
* modification date :2017-04-05
* explain :
* The following code is just a sample code for the convenience of merchant testing , Merchants can according to their own website needs , Prepared according to technical documents , It's not necessary to use this code .
* This code is for studying and studying Alipay interface only. , Just a reference .
*/
public class AlipayConfig {
//↓↓↓↓↓↓↓↓↓↓ Please configure your basic information here ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
// application ID, Your APPID, The collection account is your APPID Corresponding Alipay account number
public static String app_id = "";
// Merchants private key , Your PKCS8 Format RSA2 Private key
public static String merchant_private_key = "";
// Alipay public key , Check the address :https://openhome.alipay.com/platform/keyManage.htm Corresponding APPID Alipay public key .
public static String alipay_public_key = "";
// Server asynchronous notification page path Need to be http:// Full path to format , Cannot add ?id=123 Such custom parameters , The Internet must be accessible
// The address to jump after successful payment Change to the address where you modify the order status .
// public static String return_url = "http:// This machine ip Address :8081/order/updateOrderStatus";
public static String notify_url = "http:// Access address of the project public network /alipay.trade.page.pay-JAVA-UTF-8/notify_url.jsp";
// Page Jump synchronization notification page path Need to be http:// Full path to format , Cannot add ?id=123 Such custom parameters , The Internet must be accessible
public static String return_url = "http:// Access address of the project public network /alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp";
// Signature method
public static String sign_type = "RSA2";
// Character encoding format
public static String charset = "utf-8";
// Alipay gateway
public static String gatewayUrl = "https://openapi.alipay.com/gateway.do";
// Alipay gateway
public static String log_path = "C:\\";
//↑↑↑↑↑↑↑↑↑↑ Please configure your basic information here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
/**
* Write the log , Convenient test ( See website requirements , It can also be changed to store records in the database )
* @param sWord To write the text content in the log
*/
public static void logResult(String sWord) {
FileWriter writer = null;
try {
writer = new FileWriter(log_path + "alipay_log_" + System.currentTimeMillis()+".txt");
writer.write(sWord);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
Submit button of shopping cart page , When you click Submit , The page jumps to ShopcarController class , Sandbox payment page go , Pay and arrive OrderController Class .
submit();
function submit() {
// Get all the product information and submit it to the background
$.ajax({
url: "/shopcar/shopCarBalance",
data: {
bookid: bookid,
ids: ids,
totalcount: total_count,
totalprice: total_price,
cname: addName,
phone: addPhone,
address: addAddrerss,
express: express
},
dataType: "json",
type: "post",
success: function (addOrderObj) {
if (addOrderObj.code == 1) {
location.href="/shopcar/pay?orderno="+addOrderObj.data.ordernumber+"&money="+addOrderObj.data.totalprice;
} else {
layer.msg(" Failed to submit order !", {icon: 5})
}
}
})
}
}
ShopcarController class , Sandbox payment page
/**
* Confirmation of order
*/
@RestController
@RequestMapping("/shopcar")
public class ShopcarController {
@Autowired
private ShopcarMapper shopcarMapper;
@Autowired
private AddressMapper addressMapper;
@Autowired
private BookMapper bookMapper;
@Autowired
private OrderMapper orderMapper;
@Autowired
private Order_detailMapper orderDetailMapper;
@Autowired
private BooktypeMapper bookTypeMapper;
/**
* Add it to the order when paying
* @param order
* @param session
* @return
// */
// shopCarBalance
@RequestMapping("shopCarBalance")
public CommonResult shopCarBalance(Order order, HttpSession session, Integer bookid, String ids,String count, String price){
User user = (User) session.getAttribute("user");
order.setPname(user.getName()); // The name of the next person
order.setUid(user.getUid()); // The number of the next person
long orderNo = new Date().getTime();
order.setOrderNumber(orderNo+""+user.getUid()); // The order number
order.setStatus(5); // The order status 5 Did not pay
order.setPdate(new Date()); // Order time
System.out.println(order);
orderMapper.insert(order);
System.out.println("~~~~~~~~~~~~bookid==========="+bookid);
if (bookid !=null ){
// Add a Book
Book book = bookMapper.selectByPrimaryKey(bookid); // According to the book id Search for book information
Order_detail orderDetail = new Order_detail();
orderDetail.setBookid(book.getBookid());
orderDetail.setBookname(book.getBookname());
orderDetail.setAuthor(book.getBookauthor());
orderDetail.setPublisher(book.getBookpublisher());
Integer count1 = Integer.valueOf(count);
orderDetail.setCount(count1);
orderDetail.setPrice(price);
Booktype booktype = bookTypeMapper.selectByPrimaryKey(book.getTypeid());
orderDetail.setBooktype(booktype.getBookType());
orderDetail.setUrl(book.getUrl());
orderDetail.setPid(order.getPid());
orderDetail.setStatus(0);
orderDetailMapper.insert(orderDetail);
}
// Add multiple
System.out.println("~~~~~~~~~ids~~~~~"+ids);
if (ids!=null && ids!=""){
String[] split = ids.split(",");// Multiple bookid
for (String s:split){
System.out.println(s);
}
System.out.println(split+"===========");
for (String s:split){
Integer ss = Integer.valueOf(s);
Shopcar shopcar = shopcarMapper.selectByPrimaryKey(ss);
Book book = bookMapper.selectByPrimaryKey(shopcar.getBookid());
System.out.println(book);
Order_detail orderDetail = new Order_detail();
orderDetail.setBookid(book.getBookid());
orderDetail.setBookname(book.getBookname());
orderDetail.setAuthor(book.getBookauthor());
orderDetail.setPublisher(book.getBookpublisher());
orderDetail.setCount(shopcar.getCount());
orderDetail.setPrice(shopcar.getPrice());
Booktype booktype = bookTypeMapper.selectByPrimaryKey(book.getTypeid());
orderDetail.setBooktype(booktype.getBookType());
orderDetail.setUrl(book.getUrl());
orderDetail.setPid(order.getPid());
orderDetail.setStatus(0);
orderDetailMapper.insert(orderDetail);
}
}
return new CommonResult(1," Order added successfully ",order);
}
/* The sandbox */
@RequestMapping("pay")
public String pay(String orderno, String money, HttpServletRequest request){
try {
// Get initialized AlipayClient
AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
// Set request parameters
AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
alipayRequest.setReturnUrl(AlipayConfig.return_url);
alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
// Merchant order number , The unique order number in the order system of the merchant website , Required
String out_trade_no = new String(orderno.getBytes("ISO-8859-1"), "UTF-8");
// The payment amount , Required
String total_amount = new String(money.getBytes("ISO-8859-1"), "UTF-8");
// Name of the order , Required
String subject = new String("qy143 Book management ".getBytes("ISO-8859-1"), "UTF-8");
// Commodity Description , Can be empty
alipayRequest.setBizContent("{\"out_trade_no\":\"" + out_trade_no + "\","
+ "\"total_amount\":\"" + total_amount + "\","
+ "\"subject\":\"" + subject + "\","
+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
// If you want to BizContent Add other optional request parameters , To add custom timeout parameters timeout_express To illustrate
//alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
// + "\"total_amount\":\""+ total_amount +"\","
// + "\"subject\":\""+ subject +"\","
// + "\"body\":\""+ body +"\","
// + "\"timeout_express\":\"10m\","
// + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
// Request parameters are available 【 Paid by computer website API file -alipay.trade.page.pay- Request parameters 】 chapter
// request
String result = alipayClient.pageExecute(alipayRequest).getBody();
return result;
}catch (Exception e){
e.printStackTrace();
}
return null;
// Output
}
}
OrderController The user payment successfully jumps to this page
@Controller
@RequestMapping("order")
public class OrderController {
@Autowired
ShopcarMapper shopcarMapper;
@Autowired
private OrderMapper orderMapper;
@Autowired
Order_detailMapper order_detailMapper;
@RequestMapping("updateOrderStatus")
public String updateOrderStatus(String out_trade_no){
System.out.println(out_trade_no);
Order order=new Order();
order.setOrderNumber(out_trade_no);
order.setStatus(0);
orderMapper.updateOrderStatus(order);
return "redirect:/gereng.jsp";
}
}
边栏推荐
- Deep learning, thinking from one dimensional input to multi-dimensional feature input
- Final review Day8
- "C and pointer" - Chapter 13 function of function pointer 1 - callback function 1
- mapbox尝鲜值之云图动画
- Life is a process of continuous learning
- Using the ethtool command by example
- Altaro virtual machine replication failed: "unsupported file type vmgs"
- Altaro requirements for starting from backup on Hyper-V
- pytorch 多分类中的损失函数
- Qt读写Excel--QXlsx插入图表5
猜你喜欢

今天很多 CTO 都是被幹掉的,因為他沒有成就業務

Altaro set grandfather parent child (GFS) archiving
![[branch and cycle] | | super long detailed explanation + code analysis + a trick game](/img/aa/543d4f0dcbcd664be963579af77ec9.jpg)
[branch and cycle] | | super long detailed explanation + code analysis + a trick game

大二困局(复盘)
![[set theory] relational closure (relational closure related theorem)](/img/6a/b6dca7abf592f8d8ab1d6aecc43381.jpg)
[set theory] relational closure (relational closure related theorem)
![[set theory] relational closure (reflexive closure | symmetric closure | transitive closure)](/img/c8/2995c503e9dabae4e2cc704449e04f.jpg)
[set theory] relational closure (reflexive closure | symmetric closure | transitive closure)

一起上水碩系列】Day 9

Pytorch dataloader implements minibatch (incomplete)

2022.DAY592

PHP notes are super detailed!!!
随机推荐
Installation du plug - in CAD et chargement automatique DLL, Arx
Analysis of the example of network subnet division in secondary vocational school
[together Shangshui Shuo series] day 7 content +day8
Final review (day3)
mapbox尝鲜值之云图动画
[set theory] relational closure (reflexive closure | symmetric closure | transitive closure)
1. Somme des deux nombres
Common exceptions when Jenkins is released (continuous update...)
Apache+PHP+MySQL环境搭建超详细!!!
Installation of CAD plug-ins and automatic loading of DLL and ARX
MySQL startup error: several solutions to the server quit without updating PID file
Configure DTD of XML file
Apt update and apt upgrade commands - what is the difference?
Yum is too slow to bear? That's because you didn't do it
【无标题】
The programmer shell with a monthly salary of more than 10000 becomes a grammar skill for secondary school. Do you often use it!!!
NG Textarea-auto-resize
How does win7 solve the problem that telnet is not an internal or external command
How to create and configure ZABBIX
期末复习DAY8