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 #默認(rèn)false,為true表示使用沙箱環(huán)境 sign-type: RSA2 #簽名算法 app-id: #應(yīng)用ID private-key: #應(yīng)用私鑰 alipay-public-key: #支付寶公鑰
增加控制器實(shí)現(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", "測試訂單"); //訂單標(biāo)題 //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())) { //這里處理驗(yàn)簽失敗 } request.getParameter("trade_no");//獲取請求參數(shù)中的商戶訂單號 return "success"; } }
總結(jié)
以上所述是小編給大家介紹的spring boot 下支付寶的開箱既用環(huán)境,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Spring Boot 深入分析AutoConfigurationImportFilter自動化條件
這篇文章主要分析了Spring Boot AutoConfigurationImportFilter自動化條件配置源碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-07-07Spring中使用copyProperties方法進(jìn)行對象之間的屬性賦值詳解
這篇文章主要介紹了Spring中使用copyProperties方法進(jìn)行對象之間的屬性賦值詳解,使用org.springframework.beans.BeanUtils.copyProperties方法進(jìn)行對象之間屬性的賦值,避免通過get、set方法一個一個屬性的賦值,需要的朋友可以參考下2023-12-12Spring中IoC優(yōu)點(diǎn)與缺點(diǎn)解析
這篇文章主要為大家詳細(xì)解析了Spring中IoC優(yōu)點(diǎn)與缺點(diǎn),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-11-11