spring boot 下支付寶的開箱既用環(huán)境
更新時間:2017年10月31日 16:26:35 投稿:mrr
這篇文章主要介紹了spring boot 下支付寶的開箱既用環(huán)境包括使用場景和使用技巧,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
sdk-alipay
spring boot下支付寶的開箱既用環(huán)境
使用場景
spring boot應(yīng)用中需要接入支付寶
開始使用
pom.xml中引入依賴
<dependency> <groupId>net.guerlab</groupId> <artifactId>sdk-alipay-starter</artifactId> <version>1.0.3</version> </dependency>
bootstrap.yml中增加配置
sdk: alipay: dev: true/false #默認false,為true表示使用沙箱環(huán)境 sign-type: RSA2 #簽名算法 app-id: #應(yīng)用ID private-key: #應(yīng)用私鑰 alipay-public-key: #支付寶公鑰
增加控制器實現(xiàn)
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import net.guerlab.sdk.alipay.controller.AlipayAbstractController;
@RequestMapping("/pay/alipay")
public class AlipayController extends AlipayAbstractController {
@Autowired
private AlipayClient client;//支付寶請求sdk客戶端
/**
* 支付請求
*/
@GetMapping("/app/{orderId}")
public String app(
@PathVariable Long orderId,
HttpServletResponse httpResponse) {
JSONObject data = new JSONObject();
data.put("out_trade_no", "201701010000001234"); //商戶訂單號
data.put("product_code", "QUICK_MSECURITY_PAY"); //產(chǎn)品碼, APP支付 QUICK_MSECURITY_PAY, PC支付 FAST_INSTANT_TRADE_PAY, 移動H5支付 QUICK_WAP_PAY
data.put("total_amount", "0.01"); //訂單金額
data.put("subject", "測試訂單"); //訂單標題
//APP支付
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
//PC支付
//AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
//移動H5支付
//AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
request.setNotifyUrl("http://demo/pay/alipay/notify/1"); //異步通知地址
request.setBizContent(data.toJSONString()); //業(yè)務(wù)參數(shù)
return client.sdkExecute(request).getBody();
}
@PostMapping("/notify/{orderId}")
public String notify(
@PathVariable Long orderId,
HttpServletRequest request) {
if (!notify0(request.getParameterMap())) {
//這里處理驗簽失敗
}
request.getParameter("trade_no");//獲取請求參數(shù)中的商戶訂單號
return "success";
}
}
總結(jié)
以上所述是小編給大家介紹的spring boot 下支付寶的開箱既用環(huán)境,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Spring Boot中的SpringSecurity基礎(chǔ)教程
Spring Security是一個功能強大且高度可定制的身份驗證和訪問控制框架。它實際上是保護基于spring的應(yīng)用程序的標準Spring Security是一個框架,側(cè)重于為Java應(yīng)用程序提供身份驗證和授權(quán),這篇文章主要介紹了Spring Boot中的SpringSecurity學(xué)習,需要的朋友可以參考下2023-01-01
基于spring+quartz的分布式定時任務(wù)框架實現(xiàn)
在Spring中的定時任務(wù)功能,最好的辦法當然是使用Quartz來實現(xiàn)。這篇文章主要介紹了基于spring+quartz的分布式定時任務(wù)框架實現(xiàn),有興趣的可以了解一下。2017-01-01
IntelliJ?IDEA?2022.2?正式發(fā)布新功能體驗
IntelliJ?IDEA?2022.2為遠程開發(fā)功能帶來了多項質(zhì)量改進,使其更美觀、更穩(wěn)定,新版本還具有多項值得注意的升級和改進,下面跟隨小編一起看看IDEA?2022.2新版本吧2022-08-08

