赞
踩
由于前几天公司要求我来做支付模块,于是我在总结了各路大佬的代码之后加上了自己的需求,现在把代码和步骤给大家分享出来,希望可以帮到大家.
网址:https://openhome.alipay.com/platform/appDaily.htm?tab=info
1.appid(测试阶段可以先使用沙箱提供的)
2.alipayPublicKey(支付宝公钥)
3.appPrivateKey(应用私钥===通过支付宝开放平台开发助手获取)
4.gatewayUrl:https://openapi.alipaydev.com/gateway.do
5.returnUrl:http://s9v2cw.natappfree.cc/alipay/return
6.notifyUrl:http://s9v2cw.natappfree.cc/alipay/notify
pay:
alipay:
gatewayUrl: https://openapi.alipaydev.com/gateway.do
appid: 2016101600702754
appPrivateKey: MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCV8ZnaVRUgwgKRikp7cIOrOcRhduZAD+6ky9RONNF5dnCST5m/AwJWjlWL0g6Nev66BSXPZaq7Cad+WA4PCDogKphkKpVd7C+MGSpXR64kzyVTeZJ1AIeoFKmtAhD36CWb2rt2yxpONu7nBusF2C0i2UGV5N4tiR/AFjtKFYjKqLS0U05saNWgD+pro3iiAKu5Y9F5Jqrid1BzQhyJrEqxh0FMRdedRCrqGhPeMX2PdjLkep8X1cxXsC82+++X0OF9F+Hl+OnFkxHkmCsEZETf2Mw2jXQGpwkVQlikF5ORTLtWBIMbyDHCoKev0sQqAU5Umt23ZYCPN7Btit2fO+JLAgMBAAECggEAbU0RpusQnLFwJ+GUC8ln4cAZXCbNDvPONUjz+RJdhFoHE1B9NZUe9jOJPoQf4Zg/6R/pgPaObwtJkjrj/Kc1n88NCS9VdIK/4jNR/w+cbO6nOeNMFIgPW0G8sgXokp4iFCttLdo90bgPjE8psTf1JwsR2Q9dufnUMDTEgWuTLI6LvXOnwbTcTVI6FJRXstBhKJ0bfjt/Oe6kt0o5lW19Nf+6jbFl9hGykpEibB9YGeDhsAgBZaypQzVz83e/gyT7+xzyVO16dHWjzgwmuSqJXbMQJL3uetyyoVoCLeWukUyz1bywM8g9U9PC0eG8cS1UGzlvuHMZI0bHy5N1GBVlKQKBgQDzrQkjLxFauyAZrikFaeewwohNqoe1GaKFAGMlyUJBFXnlnf6e+miuhM72tpEJIbbrjgHayM+bSN677DEzPY3rdrmgu8vJq4fx5jS/+EAhopfSk7sHz9BYtgF4Ns8miNPI6J8MoLwRBff2JzyQ0bXrvDuzqadEgh8Z589qwNVLbQKBgQCdhvq/MjE+8MFTpJXDAkvKm44Qu6w3CkcFqmy2VNwezO8w8W2TO5eX6ppN8FT0iZBsuyhUsG8SbEvib9aL34uUxQ6ZzwKYzmT/z6kzNrQnkVx8x6mWonS5cE6BnGnH+wrLF6DAY+18g752Wq/Kt5xHNvryVbSqi4dxSHWzs1HZlwKBgD5Yh335DPep6QypAtXfwuf23ekBOLedV3ewIa4JUGpWlFmrkvoaF66PTGTTUUiE18htDQxtVLDmdBag1/XESgt01QnLAtkWijHaNKTpX387mpzGL5RQF36bEsUvQNEbMRS2b/tLJNM2M7tHTre+8EzgXGYbgjCFGnAGX4twyyIBAoGBAIIiqXFcSLyjbkLoO+SfN/fILEP8lpfdwLCYizjRwAsd6Bg5yvkQCPsyj4kFm1ltb8ezkezs2MWSe9oz5D0nTwt3A8ni71VHZL7EUhaCAbCScKKQ27Qav20Wr3R5wBW6eb8v5NgrdV0hBS6HWqSQrOVUMVoTna4qmJjocHwlDuA/AoGBAMMbSjobXgxM9gqQSCfIxgQq7d5MHfX9/SveiSKvw2O7yDFz20vpWBTvBAK5Uoguru+OiaNcxhWeIhR4GL0Tl/J6HPYbNJ3OSNRubog5JVs3IvH1rd9jxLeSc42hxHEkpSaTXayFiYusfb5lAnQuHX1Imvglm7ePESWl2JbEr973
alipayPublicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl6JiPLmQ5pn8pwtR+DAdGZrVAHbfvf05Fejd303mk9dZQds2kRGMKfV8qkyUyuWZkYbN4KLIzP76dF3/TzGT1Z8H29NpVpsKYaN07kFql4BgxhsJGZs/ORE5aSiSdrBgClEgvToGU721uA3IffRX4GACrSUGvTSPut4/rcsF4+qJxMvH029af1PRWjRQmpxKhaqO0j2LGGTgkqhs1dcKRUUY6fFfc2eq1mIe9i0UlZ/P/ZzXLDXchQrD5QsbHLMqqhPkrVcwsL5etxzcezUhLRxWd6um/cGp1iZ8BDzd8OFXu++mXVq2Jbmo1ClzuWnOOv9nPayq6SwBZOp+KB7ftwIDAQAB
returnUrl: http://s9v2cw.natappfree.cc/alipay/return
notifyUrl: http://s9v2cw.natappfree.cc/alipay/notify
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.mk.mkqy</groupId> <artifactId>yunju</artifactId> <version>0.0.1-SNAPSHOT</version> <name>yunju</name> <description>云聚app后台</description> <properties> <java.version>1.8</java.version> <commons-lang-version>2.6</commons-lang-version> <commons-fileupload-version>1.3.1</commons-fileupload-version> <commons-io-version>2.5</commons-io-version> <commons-codec-version>1.10</commons-codec-version> <commons-configuration-version>1.10</commons-configuration-version> <shiro-version>1.3.2</shiro-version> <qiniu-version>7.2.11</qiniu-version> <fastjson-version>1.2.32</fastjson-version> <aliyun-oss-version>2.5.0</aliyun-oss-version> <qcloud-cos-version>4.4</qcloud-cos-version> <kaptcha-version>0.0.9</kaptcha-version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.10</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.msgpack</groupId> <artifactId>msgpack</artifactId> <version>0.6.12</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>javax.mail-api</artifactId> <version>1.6.2</version> </dependency> <dependency > <groupId >com.sun.mail </groupId > <artifactId >javax.mail </artifactId > <version >1.6.2</version > </dependency > <!-- <dependency>--> <!-- <groupId>io.springfox</groupId>--> <!-- <artifactId>springfox-swagger2</artifactId>--> <!-- <version>2.5.0</version>--> <!-- </dependency>--> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> <version>1.9.6</version> </dependency> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-spring-boot-starter</artifactId> <version>1.9.6</version> </dependency> <!-- <dependency>--> <!-- <groupId>io.springfox</groupId>--> <!-- <artifactId>springfox-swagger-ui</artifactId>--> <!-- <version>2.5.0</version>--> <!-- </dependency>--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.0.6</version> </dependency> <!-- 阿里云短信验证--> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-dysmsapi</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.0.6</version> <!-- 注:如提示报错,先升级基础包版,无法解决可联系技术支持 --> </dependency> <!--百度地图--> <!--<dependency> <groupId>com.baidu.mapapi</groupId> <artifactId>search</artifactId> <version>3.7.1</version> </dependency>--> <!-- velocity 模板引擎 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>2.0</version> </dependency> <!-- freemarker 模板引擎 --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.28</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <!-- Spring Boot Redis 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!-- Spring Boot Cache 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>com.alipay.sdk</groupId> <artifactId>alipay-sdk-java</artifactId> <version>3.4.49.ALL</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.6</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> <!-- 这个需要为 true 热部署才有效 --> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-extension</artifactId> <version>3.0.6</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-extension</artifactId> <version>3.0.6</version> </dependency> <!-- java 根据经纬度获取地址--> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> <classifier>jdk15</classifier> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>4.1.19</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-dbcp2</artifactId> <version>2.1.1</version> </dependency> <!--easy-rules--> <dependency> <groupId>org.jeasy</groupId> <artifactId>easy-rules-core</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>org.jeasy</groupId> <artifactId>easy-rules-mvel</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.30.Final</version> <scope>compile</scope> </dependency> <!--Netty实现聊天--> <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.25.Final</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.0.6</version> </dependency> <dependency> <groupId>com.google.android</groupId> <artifactId>android</artifactId> <version>4.1.1.4</version> <scope>provided</scope> </dependency> <!-- velocity 模板引擎 --> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>2.0</version> </dependency> <!-- 阿里云短信验证--> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-dysmsapi</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.0.6</version> <!-- 注:如提示报错,先升级基础包版,无法解决可联系技术支持 --> </dependency> <!-- freemarker 模板引擎 --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.28</version> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>javax.mail-api</artifactId> <version>1.6.2</version> </dependency> <dependency > <groupId >com.sun.mail </groupId > <artifactId >javax.mail </artifactId > <version >1.6.2</version > </dependency > <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <!-- Spring Boot Redis 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!-- Spring Boot Cache 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>com.alipay.sdk</groupId> <artifactId>alipay-sdk-java</artifactId> <version>3.4.49.ALL</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.6</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.0.1</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.0.1</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>4.0.1</version> </dependency> <dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> <version>3.0.2</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.28</version> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>4.5.7</version> <scope>compile</scope> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>4.5.7</version> </dependency> <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId> <version>1.6.2</version> </dependency> <dependency> <groupId>org.jeasy</groupId> <artifactId>easy-rules-core</artifactId> <version>RELEASE</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.jeasy</groupId> <artifactId>easy-rules-support</artifactId> <version>RELEASE</version> <scope>compile</scope> </dependency> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> <classifier>jdk15</classifier> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>RELEASE</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>RELEASE</version> <scope>test</scope> </dependency> <!--开始引入支付依赖--> <dependency> <groupId>com.alipay</groupId> <artifactId>alipay-sdk-java</artifactId> <version>3.3.0</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/jar/alipay-sdk-java-3.3.0.jar</systemPath> </dependency> <dependency> <groupId>com.alipay</groupId> <artifactId>alipay-trade-java</artifactId> <version>20161215</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/jar/alipay-trade-sdk-20161215.jar</systemPath> </dependency> <!-- 跨域过滤器相关 --> <dependency> <groupId>com.thetransactioncompany</groupId> <artifactId>java-property-utils</artifactId> <version>1.9.1</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.6.2</version> </dependency> <dependency> <groupId>com.jfinal</groupId> <artifactId>jfinal</artifactId> <version>3.2</version> </dependency> <dependency> <groupId>com.jfinal</groupId> <artifactId>jfinal-weixin</artifactId> <version>1.9</version> </dependency> <dependency> <groupId>com.github.javen205</groupId> <artifactId>IJPay</artifactId> <version>0.6</version> </dependency> <!-- 微信支付 sdk --> <dependency> <groupId>com.github.wxpay</groupId> <artifactId>wxpay-sdk</artifactId> <version>0.0.3</version> </dependency> <!-- log4j --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.4.1</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.1</version> </dependency> <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.1</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.29</version> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>${commons-lang-version}</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>${commons-fileupload-version}</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>${commons-io-version}</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson-version}</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>${commons-codec-version}</version> </dependency> <dependency> <groupId>commons-configuration</groupId> <artifactId>commons-configuration</artifactId> <version>${commons-configuration-version}</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <version>${shiro-version}</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>${shiro-version}</version> </dependency> <dependency> <groupId>com.github.axet</groupId> <artifactId>kaptcha</artifactId> <version>${kaptcha-version}</version> </dependency> <dependency> <groupId>com.qiniu</groupId> <artifactId>qiniu-java-sdk</artifactId> <version>${qiniu-version}</version> </dependency> <dependency> <groupId>com.aliyun.oss</groupId> <artifactId>aliyun-sdk-oss</artifactId> <version>${aliyun-oss-version}</version> </dependency> <dependency> <groupId>com.qcloud</groupId> <artifactId>cos_api</artifactId> <version>${qcloud-cos-version}</version> </dependency> </dependencies> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </repository> <repository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/snapshot</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </pluginRepository> <pluginRepository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/snapshot</url> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </project>
其中有两个jar是需要我们自己进行导入的
package com.mk.mkqy.controller; import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayClient; import com.alipay.api.domain.AlipayTradeWapPayModel; import com.alipay.api.internal.util.AlipaySignature; import com.alipay.api.request.AlipayTradeWapPayRequest; import com.mk.mkqy.configuration.AlipayProperties; import com.mk.mkqy.entity.CustomerInf; import com.mk.mkqy.entity.Order_master; import com.mk.mkqy.mapper.CustomerInfMapper; import com.mk.mkqy.mapper.Order_masterMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.text.SimpleDateFormat; import java.util.*; @Slf4j @Controller @RequestMapping("/alipay/wap") public class AlipayWAPPayController { @Resource private AlipayProperties alipayProperties; @Resource private AlipayClient alipayClient; @Resource private Order_masterMapper order_masterMapper; @Resource private CustomerInfMapper customerInfMapper; /** * 去支付 * 支付宝返回一个form表单,并自动提交,跳转到支付宝页面 * @param response * @throws Exception */ @RequestMapping("/gotoPayPage") public void gotoPayPage(@RequestParam("oid")String oid,@RequestParam("value") String value, @RequestParam("customId")String customId, HttpServletResponse response) throws AlipayApiException, IOException { //开始通过用户的id找对象 CustomerInf customerInf=customerInfMapper.selectById(customId); //获取当前时间 SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar c = Calendar.getInstance(); //System.out.println("当前时间:"+sf.format(c.getTime())); //修改数据库当前的会员值 Date datenow = c.getTime(); System.out.println("============================================================"); System.out.println("datenow:"+datenow); //获取数据库当前会员的过期时间 if(Integer.valueOf(value)>299&&customerInf.getIsMember().equals("1")&&customerInf.getMemberEndTime().after(datenow)){ // 订单模型 String productCode="QUICK_WAP_WAY"; AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.setOutTradeNo(UUID.randomUUID().toString()); /* * 此时需要传递的是对应的商品名称和商品价格 * */ Random rand = new Random(); int randNum = rand.nextInt(10)+1; int realNum=Integer.valueOf(value)-randNum; String payMoney=String.valueOf(realNum); String name="会员享受"+randNum+"元红包"; model.setSubject(name); model.setTotalAmount(payMoney); model.setBody(name+",共"+payMoney+"元"); model.setTimeoutExpress("5m"); model.setProductCode(productCode); AlipayTradeWapPayRequest wapPayRequest =new AlipayTradeWapPayRequest(); wapPayRequest.setReturnUrl("http://geekcjj.natapp1.cc/alipay/wap/success"); /* * 开始修改对应字段的状态值 * */ Order_master order_master=new Order_master(); /*根据id找对象*/ System.out.println(oid); System.out.println(order_master); //selectByOrderId Order_master order_master1=order_masterMapper.selectById(oid); System.out.println(order_master1); //修改对应的值 order_master1.setOrderStatus(1); int num=order_masterMapper.updateById(order_master1); wapPayRequest.setNotifyUrl(alipayProperties.getNotifyUrl()); wapPayRequest.setBizModel(model); // 调用SDK生成表单, 并直接将完整的表单html输出到页面 String form = alipayClient.pageExecute(wapPayRequest).getBody(); System.out.println(form); response.setContentType("text/html;charset=" + alipayProperties.getCharset()); response.getWriter().write(form); response.getWriter().flush(); response.getWriter().close(); }else{ // 订单模型 String productCode="QUICK_WAP_WAY"; AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); model.setOutTradeNo(UUID.randomUUID().toString()); /* * 此时需要传递的是对应的商品名称和商品价格 * */ String name="应付款"; model.setSubject(name); model.setTotalAmount(value); model.setBody(name+",共"+value+"元"); model.setTimeoutExpress("5m"); model.setProductCode(productCode); AlipayTradeWapPayRequest wapPayRequest =new AlipayTradeWapPayRequest(); wapPayRequest.setReturnUrl("http://geekcjj.natapp1.cc/alipay/wap/success"); /* * 开始修改对应字段的状态值 * */ Order_master order_master=new Order_master(); /*根据id找对象*/ System.out.println(oid); System.out.println(order_master); //selectByOrderId Order_master order_master1=order_masterMapper.selectById(oid); System.out.println(order_master1); //修改对应的值 order_master1.setOrderStatus(1); int num=order_masterMapper.updateById(order_master1); wapPayRequest.setNotifyUrl(alipayProperties.getNotifyUrl()); wapPayRequest.setBizModel(model); // 调用SDK生成表单, 并直接将完整的表单html输出到页面 String form = alipayClient.pageExecute(wapPayRequest).getBody(); System.out.println(form); response.setContentType("text/html;charset=" + alipayProperties.getCharset()); response.getWriter().write(form); response.getWriter().flush(); response.getWriter().close(); } } /** * 支付宝页面跳转同步通知页面 * @param request * @return * @throws UnsupportedEncodingException * @throws AlipayApiException */ @RequestMapping("/returnUrl") public String returnUrl(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, AlipayApiException { response.setContentType("text/html;charset=" + alipayProperties.getCharset()); //获取支付宝GET过来反馈信息 Map<String,String> params = new HashMap<>(); Map requestParams = request.getParameterMap(); for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) { String name = (String) iter.next(); String[] values = (String[]) requestParams.get(name); String valueStr = ""; for (int i = 0; i < values.length; i++) { valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ","; } //乱码解决,这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化 valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8"); params.put(name, valueStr); } boolean verifyResult = AlipaySignature.rsaCheckV1(params, alipayProperties.getAlipayPublicKey(), alipayProperties.getCharset(), "RSA2"); if(verifyResult){ //验证成功 //请在这里加上商户的业务逻辑程序代码,如保存支付宝交易号 //商户订单号 String out_trade_no = new String(request.getParameter("out_trade_no").getBytes("ISO-8859-1"),"UTF-8"); //支付宝交易号 String trade_no = new String(request.getParameter("trade_no").getBytes("ISO-8859-1"),"UTF-8"); return "redirect:success"; }else{ return "wapPayFail"; } } @RequestMapping("/success") public String success(){ return "wapPaySuccess"; } }
package com.mk.mkqy.configuration; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.boot.context.properties.ConfigurationProperties; import javax.annotation.PostConstruct; @Data @Slf4j @ConfigurationProperties(prefix = "pay.alipay") public class AlipayProperties { /** 支付宝gatewayUrl */ private String gatewayUrl; /** 商户应用id */ private String appid; /** RSA私钥,用于对商户请求报文加签 */ private String appPrivateKey; /** 支付宝RSA公钥,用于验签支付宝应答 */ private String alipayPublicKey; /** 签名类型 */ private String signType = "RSA2"; /** 格式 */ private String formate = "json"; /** 编码 */ private String charset = "UTF-8"; /** 同步地址 */ private String returnUrl; /** 异步地址 */ private String notifyUrl; /** 最大查询次数 */ private static int maxQueryRetry = 5; /** 查询间隔(毫秒) */ private static long queryDuration = 5000; /** 最大撤销次数 */ private static int maxCancelRetry = 3; /** 撤销间隔(毫秒) */ private static long cancelDuration = 3000; private AlipayProperties() {} /** * PostContruct是spring框架的注解,在方法上加该注解会在项目启动的时候执行该方法,也可以理解为在spring容器初始化的时候执行该方法。 */ @PostConstruct public void init() { //log.info(description()); System.out.println(description()); } public String description() { StringBuilder sb = new StringBuilder("\nConfigs{"); sb.append("支付宝网关: ").append(gatewayUrl).append("\n"); sb.append(", appid: ").append(appid).append("\n"); sb.append(", 商户RSA私钥: ").append(getKeyDescription(appPrivateKey)).append("\n"); sb.append(", 支付宝RSA公钥: ").append(getKeyDescription(alipayPublicKey)).append("\n"); sb.append(", 签名类型: ").append(signType).append("\n"); sb.append(", 查询重试次数: ").append(maxQueryRetry).append("\n"); sb.append(", 查询间隔(毫秒): ").append(queryDuration).append("\n"); sb.append(", 撤销尝试次数: ").append(maxCancelRetry).append("\n"); sb.append(", 撤销重试间隔(毫秒): ").append(cancelDuration).append("\n"); sb.append("}"); return sb.toString(); } private String getKeyDescription(String key) { int showLength = 6; if (StringUtils.isNotEmpty(key) && key.length() > showLength) { return new StringBuilder(key.substring(0, showLength)).append("******") .append(key.substring(key.length() - showLength)).toString(); } return null; } public String getGatewayUrl() { return gatewayUrl; } public void setGatewayUrl(String gatewayUrl) { this.gatewayUrl = gatewayUrl; } public String getAppid() { return appid; } public void setAppid(String appid) { this.appid = appid; } public String getAppPrivateKey() { return appPrivateKey; } public void setAppPrivateKey(String appPrivateKey) { this.appPrivateKey = appPrivateKey; } public String getAlipayPublicKey() { return alipayPublicKey; } public void setAlipayPublicKey(String alipayPublicKey) { this.alipayPublicKey = alipayPublicKey; } public String getSignType() { return signType; } public void setSignType(String signType) { this.signType = signType; } public String getFormate() { return formate; } public void setFormate(String formate) { this.formate = formate; } public String getCharset() { return charset; } public void setCharset(String charset) { this.charset = charset; } public String getReturnUrl() { return returnUrl; } public void setReturnUrl(String returnUrl) { this.returnUrl = returnUrl; } public String getNotifyUrl() { return notifyUrl; } public void setNotifyUrl(String notifyUrl) { this.notifyUrl = notifyUrl; } public static int getMaxQueryRetry() { return maxQueryRetry; } public static void setMaxQueryRetry(int maxQueryRetry) { AlipayProperties.maxQueryRetry = maxQueryRetry; } public static long getQueryDuration() { return queryDuration; } public static void setQueryDuration(long queryDuration) { AlipayProperties.queryDuration = queryDuration; } public static int getMaxCancelRetry() { return maxCancelRetry; } public static void setMaxCancelRetry(int maxCancelRetry) { AlipayProperties.maxCancelRetry = maxCancelRetry; } public static long getCancelDuration() { return cancelDuration; } public static void setCancelDuration(long cancelDuration) { AlipayProperties.cancelDuration = cancelDuration; } }
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <base href="http://localhost:8080/"> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css"> <script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.10.2/jquery.js"></script> <style> body { margin: 20px; font-size: 5px; } </style> </head> <body> <table id="table" class="table table-hover table-bordered"> <tr class="success"> <td>订单ID</td> <td>商家id</td> <td>订单编号</td> <td>下单人ID</td> <td>收货人姓名</td> <td>收货人手机号码</td> <td>省</td> <td>市</td> <td>区</td> <td>地址</td> <td>支付方式</td> <td>订单金额</td> <td>优惠金额</td> <td>运费金额</td> <td>支付金额</td> <td>快递公司名称</td> <td>快递单号</td> <td>下单时间</td> <td>发货时间</td> <td>支付时间</td> <td>收货时间</td> <td>订单状态:0:待付款 1:待发货 2:已发货 3:退款/售后 4:完成订单 5:取消订单</td> <td>订单积分</td> <td>发票抬头</td> <td>最后修改时间</td> <td>配送方式 0:自提 1:配送 2:快递</td> <td>是否使用会员红包</td> <td>用的券ID</td> <td>是否是租赁订单</td> <td>订单备注</td> <td>其他操作</td> </tr> </table> <script type="text/javascript"> requestData(); function requestData() { $.get("/queryAll",function (result) { if (result.code==200){ for (var i=0;i<result.data.length;i++){ var order=result.data[i]; var $td=$("<td></td>").text(order.orderId); var $td1=$("<td></td>").text(order.supplierId); var $td2=$("<td></td>").text(order.orderSn); var $td3=$("<td></td>").text(order.customerId); var $td4=$("<td></td>").text(order.receiverName); var $td5=$("<td></td>").text(order.receiverPhone); var $td6=$("<td></td>").text(order.province); var $td7=$("<td></td>").text(order.city); var $td8=$("<td></td>").text(order.area); var $td9=$("<td></td>").text(order.address); var $td10=$("<td></td>").text(order.paymentMethod); var $td11=$("<td></td>").text(order.orderMoney); var $td12=$("<td></td>").text(order.discountMoney); var $td13=$("<td></td>").text(order.shippingMoney); var $td14=$("<td></td>").text(order.paymentMoney); var $td15=$("<td></td>").text(order.shippingCompName); var $td16=$("<td></td>").text(order.shippingSn); var $td17=$("<td></td>").text(order.createTime); var $td18=$("<td></td>").text(order.shippingTime); var $td19=$("<td></td>").text(order.payTime); var $td20=$("<td></td>").text(order.receiveTime); var $td21=$("<td></td>").text(order.orderStatus); var $td22=$("<td></td>").text(order.orderPoint); var $td23=$("<td></td>").text(order.invoiceTime); var $td24=$("<td></td>").text(order.modifiedTime); var $td25=$("<td></td>").text(order.shippingType); var $td26=$("<td></td>").text(order.isUseRedMoney); var $td27=$("<td></td>").text(order.couponId); var $td28=$("<td></td>").text(order.isRentOrder); var $td29=$("<td></td>").text(order.notes); var $button=$("<button></button>").addClass("glyphicon glyphicon-gbp btn btn-link"); $button.attr("oid",order.orderId); $button.attr("name",order.receiverName); $button.attr("value",order.orderMoney); $button.attr("customId",order.customerId); /* var $button2=$("<button></button>").addClass("glyphicon glyphicon-pencil btn btn-link");*/ var $td30=$("<td></td>").append($button); /*$td30.append($button2);*/ var $tr=$("<tr></tr>").append($td); $tr.append($td); $tr.append($td1); $tr.append($td2); $tr.append($td3); $tr.append($td4); $tr.append($td5); $tr.append($td6); $tr.append($td7); $tr.append($td8); $tr.append($td9); $tr.append($td10); $tr.append($td11); $tr.append($td12); $tr.append($td13); $tr.append($td14); $tr.append($td15); $tr.append($td16); $tr.append($td17); $tr.append($td18); $tr.append($td19); $tr.append($td20); $tr.append($td21); $tr.append($td22); $tr.append($td23); $tr.append($td24); $tr.append($td25); $tr.append($td26); $tr.append($td27); $tr.append($td28); $tr.append($td29); $tr.append($td30); $(table).append($tr); } } }); } $("table").delegate("button.glyphicon-gbp", "click", function() { var oid=$(this).attr("oid"); var name = $(this).attr("name"); var value=$(this).attr("value"); var customId=$(this).attr("customId"); var btn = this; $.ajax({ url:"/alipay/wap/gotoPayPage", type:"post", data:{ "oid":oid, "name":name, "value":value, "customId":customId }, success:function(result){ alert(name+value+"元"); /* $(btn).parent().parent().remove();*/ window.location.href = "/alipay/wap/gotoPayPage?oid="+oid+"&value="+value+"&customId="+customId; } }); }); /*/alipay/wap/gotoPayPage?oid="+oid+"&name="+name+"&value="+value;*/ </script> </body> </html>
动态效果我录了视频,打开抖音就可以看到哦.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。