浏览代码

支付宝启动参数加载

小柒2012 7 年之前
父节点
当前提交
ade56d372f

+ 2 - 1
.gitignore

@@ -6,4 +6,5 @@
 *.war
 *.ear
 /target/
-/.settings/
+/.settings/
+zfbinfo.properties

+ 7 - 0
pom.xml

@@ -61,6 +61,13 @@
 		    <artifactId>json-lib</artifactId>
 		    <version>2.4</version>
 		</dependency>
+		<!-- commons-configuration -->
+		<dependency>
+		    <groupId>commons-configuration</groupId>
+		    <artifactId>commons-configuration</artifactId>
+		    <version>1.10</version>
+		</dependency>
+		
 	</dependencies>
 	<build>
 		<finalName>spring-boot-pay</finalName>

+ 4 - 0
src/main/java/com/itstyle/Application.java

@@ -4,6 +4,8 @@ import org.apache.log4j.Logger;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.context.annotation.ComponentScan;
+
+import com.alipay.demo.trade.config.Configs;
 /**
  * 支付主控
  * 创建者 科帮网
@@ -17,6 +19,8 @@ public class Application  {
 	
 	public static void main(String[] args) throws InterruptedException {
 		SpringApplication.run(Application.class, args);
+		//初始化 支付宝参数 涉及机密 此文件不提交 请自行配置加载
+		Configs.init("zfbinfo.properties");
 		logger.info("支付项目启动 ");
 	}
 }

+ 5 - 2
src/main/java/com/itstyle/modules/alipay/service/IAliPayService.java

@@ -1,5 +1,4 @@
 package com.itstyle.modules.alipay.service;
-
 import com.itstyle.common.model.Product;
 /**
  * 扫码支付以及手机H5支付
@@ -56,7 +55,11 @@ public interface IAliPayService {
 	 */
 	String downloadBillUrl(String billDate,String billType);
 	/**
-	 * 手机支付返回一个form表单 然后调用方刷新到H5页面
+	 * 方法一:
+	 * 对于页面跳转类API,SDK不会也无法像系统调用类API一样自动请求支付宝并获得结果,而是在接受request请求对象后,
+	 * 为开发者生成前台页面请求需要的完整form表单的html(包含自动提交脚本),商户直接将这个表单的String输出到http response中即可。
+	 * 方法二:
+	 * 如果是远程调用返回消费放一个form表单 然后调用方刷新到页面自动提交即可
 	 * @Author  科帮网
 	 * @param product
 	 * @return  String

+ 3 - 3
src/main/java/com/itstyle/modules/alipay/service/impl/AliPayServiceImpl.java

@@ -218,8 +218,8 @@ public class AliPayServiceImpl implements IAliPayService {
 		logger.info("支付宝手机支付下单");
 		String  totalFee =  CommonUtil.divide(product.getTotalFee(), "100").toString();
 		AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();
-		String subject = "买个苹果而已";
-		String returnUrl =  "回调地址 http 自定义";
+		String subject = "我去年买个苹果而已";
+		String returnUrl = "回调地址 http 自定义";
 		alipayRequest.setReturnUrl(returnUrl);//前台通知
 		String notifyUrl  = Constants.PAY_URL.get("alipay_notify_url");
         alipayRequest.setNotifyUrl(notifyUrl);//后台回调
@@ -233,7 +233,7 @@ public class AliPayServiceImpl implements IAliPayService {
 		String biz = bizContent.toString().replaceAll("\"", "'");
         alipayRequest.setBizContent(biz);
         logger.info("业务参数:"+alipayRequest.getBizContent());
-        String form = "支付宝异常";
+        String form = Constants.FAIL;
         try {
             form = AliPayConfig.getAlipayClient().pageExecute(alipayRequest).getBody();
         } catch (AlipayApiException e) {

+ 22 - 0
src/test/java/com/itstyle/test/AliPayTest.java

@@ -0,0 +1,22 @@
+package com.itstyle.test;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import com.itstyle.common.model.Product;
+import com.itstyle.modules.alipay.service.IAliPayService;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class AliPayTest {
+	@Autowired
+	private IAliPayService aliPayService;
+	@Test
+	public void hello() {
+		Product product = new Product();
+		aliPayService.aliPay(product);
+	}
+}