| @ -0,0 +1,171 @@ | |||
| package org.jeecg.modules.teambuyCashoutLog.controller; | |||
| import java.util.Arrays; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.stream.Collectors; | |||
| import java.io.IOException; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.net.URLDecoder; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import org.jeecg.common.api.vo.Result; | |||
| import org.jeecg.common.system.query.QueryGenerator; | |||
| import org.jeecg.common.util.oConvertUtils; | |||
| import org.jeecg.modules.teambuyCashoutLog.entity.TeambuyCashoutLog; | |||
| import org.jeecg.modules.teambuyCashoutLog.service.ITeambuyCashoutLogService; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.baomidou.mybatisplus.core.metadata.IPage; | |||
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.jeecgframework.poi.excel.ExcelImportUtil; | |||
| import org.jeecgframework.poi.excel.def.NormalExcelConstants; | |||
| import org.jeecgframework.poi.excel.entity.ExportParams; | |||
| import org.jeecgframework.poi.excel.entity.ImportParams; | |||
| import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; | |||
| import org.jeecg.common.system.base.controller.JeecgController; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import org.springframework.web.multipart.MultipartHttpServletRequest; | |||
| import org.springframework.web.servlet.ModelAndView; | |||
| import com.alibaba.fastjson.JSON; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.jeecg.common.aspect.annotation.AutoLog; | |||
| /** | |||
| * @Description: 提现记录表 | |||
| * @Author: jeecg-boot | |||
| * @Date: 2025-06-12 | |||
| * @Version: V1.0 | |||
| */ | |||
| @Api(tags="提现记录表") | |||
| @RestController | |||
| @RequestMapping("/teambuyCashoutLog/teambuyCashoutLog") | |||
| @Slf4j | |||
| public class TeambuyCashoutLogController extends JeecgController<TeambuyCashoutLog, ITeambuyCashoutLogService> { | |||
| @Autowired | |||
| private ITeambuyCashoutLogService teambuyCashoutLogService; | |||
| /** | |||
| * 分页列表查询 | |||
| * | |||
| * @param teambuyCashoutLog | |||
| * @param pageNo | |||
| * @param pageSize | |||
| * @param req | |||
| * @return | |||
| */ | |||
| //@AutoLog(value = "提现记录表-分页列表查询") | |||
| @ApiOperation(value="提现记录表-分页列表查询", notes="提现记录表-分页列表查询") | |||
| @GetMapping(value = "/list") | |||
| public Result<IPage<TeambuyCashoutLog>> queryPageList(TeambuyCashoutLog teambuyCashoutLog, | |||
| @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, | |||
| @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, | |||
| HttpServletRequest req) { | |||
| QueryWrapper<TeambuyCashoutLog> queryWrapper = QueryGenerator.initQueryWrapper(teambuyCashoutLog, req.getParameterMap()); | |||
| Page<TeambuyCashoutLog> page = new Page<TeambuyCashoutLog>(pageNo, pageSize); | |||
| IPage<TeambuyCashoutLog> pageList = teambuyCashoutLogService.page(page, queryWrapper); | |||
| return Result.OK(pageList); | |||
| } | |||
| /** | |||
| * 添加 | |||
| * | |||
| * @param teambuyCashoutLog | |||
| * @return | |||
| */ | |||
| @AutoLog(value = "提现记录表-添加") | |||
| @ApiOperation(value="提现记录表-添加", notes="提现记录表-添加") | |||
| @PostMapping(value = "/add") | |||
| public Result<String> add(@RequestBody TeambuyCashoutLog teambuyCashoutLog) { | |||
| teambuyCashoutLogService.save(teambuyCashoutLog); | |||
| return Result.OK("添加成功!"); | |||
| } | |||
| /** | |||
| * 编辑 | |||
| * | |||
| * @param teambuyCashoutLog | |||
| * @return | |||
| */ | |||
| @AutoLog(value = "提现记录表-编辑") | |||
| @ApiOperation(value="提现记录表-编辑", notes="提现记录表-编辑") | |||
| @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) | |||
| public Result<String> edit(@RequestBody TeambuyCashoutLog teambuyCashoutLog) { | |||
| teambuyCashoutLogService.updateById(teambuyCashoutLog); | |||
| return Result.OK("编辑成功!"); | |||
| } | |||
| /** | |||
| * 通过id删除 | |||
| * | |||
| * @param id | |||
| * @return | |||
| */ | |||
| @AutoLog(value = "提现记录表-通过id删除") | |||
| @ApiOperation(value="提现记录表-通过id删除", notes="提现记录表-通过id删除") | |||
| @DeleteMapping(value = "/delete") | |||
| public Result<String> delete(@RequestParam(name="id",required=true) String id) { | |||
| teambuyCashoutLogService.removeById(id); | |||
| return Result.OK("删除成功!"); | |||
| } | |||
| /** | |||
| * 批量删除 | |||
| * | |||
| * @param ids | |||
| * @return | |||
| */ | |||
| @AutoLog(value = "提现记录表-批量删除") | |||
| @ApiOperation(value="提现记录表-批量删除", notes="提现记录表-批量删除") | |||
| @DeleteMapping(value = "/deleteBatch") | |||
| public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) { | |||
| this.teambuyCashoutLogService.removeByIds(Arrays.asList(ids.split(","))); | |||
| return Result.OK("批量删除成功!"); | |||
| } | |||
| /** | |||
| * 通过id查询 | |||
| * | |||
| * @param id | |||
| * @return | |||
| */ | |||
| //@AutoLog(value = "提现记录表-通过id查询") | |||
| @ApiOperation(value="提现记录表-通过id查询", notes="提现记录表-通过id查询") | |||
| @GetMapping(value = "/queryById") | |||
| public Result<TeambuyCashoutLog> queryById(@RequestParam(name="id",required=true) String id) { | |||
| TeambuyCashoutLog teambuyCashoutLog = teambuyCashoutLogService.getById(id); | |||
| if(teambuyCashoutLog==null) { | |||
| return Result.error("未找到对应数据"); | |||
| } | |||
| return Result.OK(teambuyCashoutLog); | |||
| } | |||
| /** | |||
| * 导出excel | |||
| * | |||
| * @param request | |||
| * @param teambuyCashoutLog | |||
| */ | |||
| @RequestMapping(value = "/exportXls") | |||
| public ModelAndView exportXls(HttpServletRequest request, TeambuyCashoutLog teambuyCashoutLog) { | |||
| return super.exportXls(request, teambuyCashoutLog, TeambuyCashoutLog.class, "提现记录表"); | |||
| } | |||
| /** | |||
| * 通过excel导入数据 | |||
| * | |||
| * @param request | |||
| * @param response | |||
| * @return | |||
| */ | |||
| @RequestMapping(value = "/importExcel", method = RequestMethod.POST) | |||
| public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { | |||
| return super.importExcel(request, response, TeambuyCashoutLog.class); | |||
| } | |||
| } | |||
| @ -0,0 +1,82 @@ | |||
| package org.jeecg.modules.teambuyCashoutLog.entity; | |||
| import java.io.Serializable; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.util.Date; | |||
| import java.math.BigDecimal; | |||
| import com.baomidou.mybatisplus.annotation.IdType; | |||
| import com.baomidou.mybatisplus.annotation.TableId; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import lombok.Data; | |||
| import com.fasterxml.jackson.annotation.JsonFormat; | |||
| import org.springframework.format.annotation.DateTimeFormat; | |||
| import org.jeecgframework.poi.excel.annotation.Excel; | |||
| import org.jeecg.common.aspect.annotation.Dict; | |||
| import io.swagger.annotations.ApiModel; | |||
| import io.swagger.annotations.ApiModelProperty; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.experimental.Accessors; | |||
| /** | |||
| * @Description: 提现记录表 | |||
| * @Author: jeecg-boot | |||
| * @Date: 2025-06-12 | |||
| * @Version: V1.0 | |||
| */ | |||
| @Data | |||
| @TableName("teambuy_cashout_log") | |||
| @Accessors(chain = true) | |||
| @EqualsAndHashCode(callSuper = false) | |||
| @ApiModel(value="teambuy_cashout_log对象", description="提现记录表") | |||
| public class TeambuyCashoutLog implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| /**主键*/ | |||
| @TableId(type = IdType.ASSIGN_ID) | |||
| @ApiModelProperty(value = "主键") | |||
| private java.lang.String id; | |||
| /**创建人*/ | |||
| @ApiModelProperty(value = "创建人") | |||
| private java.lang.String createBy; | |||
| /**创建日期*/ | |||
| @ApiModelProperty(value = "创建日期") | |||
| private java.util.Date createTime; | |||
| /**更新人*/ | |||
| @ApiModelProperty(value = "更新人") | |||
| private java.lang.String updateBy; | |||
| /**更新日期*/ | |||
| @ApiModelProperty(value = "更新日期") | |||
| private java.util.Date updateTime; | |||
| /**提现者姓名*/ | |||
| @Excel(name = "提现者姓名", width = 15) | |||
| @ApiModelProperty(value = "提现者姓名") | |||
| private java.lang.String realName; | |||
| /**提现金额*/ | |||
| @Excel(name = "提现金额", width = 15) | |||
| @ApiModelProperty(value = "提现金额") | |||
| private java.math.BigDecimal amount; | |||
| /**到账时间*/ | |||
| @Excel(name = "到账时间", width = 15) | |||
| @ApiModelProperty(value = "到账时间") | |||
| private java.util.Date paymentTime; | |||
| /**提现状态*/ | |||
| @Excel(name = "提现状态", width = 15) | |||
| @ApiModelProperty(value = "提现状态") | |||
| private java.lang.String status; | |||
| /**商户单号*/ | |||
| @Excel(name = "商户单号", width = 15) | |||
| @ApiModelProperty(value = "商户单号") | |||
| private java.lang.String outBillNo; | |||
| /**微信转账单号*/ | |||
| @Excel(name = "微信转账单号", width = 15) | |||
| @ApiModelProperty(value = "微信转账单号") | |||
| private java.lang.String transferBillNo; | |||
| /**领取转账信息参数*/ | |||
| @Excel(name = "领取转账信息参数", width = 15) | |||
| @ApiModelProperty(value = "领取转账信息参数") | |||
| private java.lang.String packageInfo; | |||
| /**关联用户id*/ | |||
| @Excel(name = "关联用户id", width = 15) | |||
| @ApiModelProperty(value = "关联用户id") | |||
| private java.lang.String userId; | |||
| } | |||
| @ -0,0 +1,17 @@ | |||
| package org.jeecg.modules.teambuyCashoutLog.mapper; | |||
| import java.util.List; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import org.jeecg.modules.teambuyCashoutLog.entity.TeambuyCashoutLog; | |||
| import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
| /** | |||
| * @Description: 提现记录表 | |||
| * @Author: jeecg-boot | |||
| * @Date: 2025-06-12 | |||
| * @Version: V1.0 | |||
| */ | |||
| public interface TeambuyCashoutLogMapper extends BaseMapper<TeambuyCashoutLog> { | |||
| } | |||
| @ -0,0 +1,5 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="org.jeecg.modules.teambuyCashoutLog.mapper.TeambuyCashoutLogMapper"> | |||
| </mapper> | |||
| @ -0,0 +1,14 @@ | |||
| package org.jeecg.modules.teambuyCashoutLog.service; | |||
| import org.jeecg.modules.teambuyCashoutLog.entity.TeambuyCashoutLog; | |||
| import com.baomidou.mybatisplus.extension.service.IService; | |||
| /** | |||
| * @Description: 提现记录表 | |||
| * @Author: jeecg-boot | |||
| * @Date: 2025-06-12 | |||
| * @Version: V1.0 | |||
| */ | |||
| public interface ITeambuyCashoutLogService extends IService<TeambuyCashoutLog> { | |||
| } | |||
| @ -0,0 +1,19 @@ | |||
| package org.jeecg.modules.teambuyCashoutLog.service.impl; | |||
| import org.jeecg.modules.teambuyCashoutLog.entity.TeambuyCashoutLog; | |||
| import org.jeecg.modules.teambuyCashoutLog.mapper.TeambuyCashoutLogMapper; | |||
| import org.jeecg.modules.teambuyCashoutLog.service.ITeambuyCashoutLogService; | |||
| import org.springframework.stereotype.Service; | |||
| import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||
| /** | |||
| * @Description: 提现记录表 | |||
| * @Author: jeecg-boot | |||
| * @Date: 2025-06-12 | |||
| * @Version: V1.0 | |||
| */ | |||
| @Service | |||
| public class TeambuyCashoutLogServiceImpl extends ServiceImpl<TeambuyCashoutLogMapper, TeambuyCashoutLog> implements ITeambuyCashoutLogService { | |||
| } | |||
| @ -0,0 +1,213 @@ | |||
| <template> | |||
| <a-card :bordered="false"> | |||
| <!-- 查询区域 --> | |||
| <div class="table-page-search-wrapper"> | |||
| <a-form layout="inline" @keyup.enter.native="searchQuery"> | |||
| <a-row :gutter="24"> | |||
| </a-row> | |||
| </a-form> | |||
| </div> | |||
| <!-- 查询区域-END --> | |||
| <!-- 操作按钮区域 --> | |||
| <div class="table-operator"> | |||
| <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> | |||
| <a-button type="primary" icon="download" @click="handleExportXls('提现记录表')">导出</a-button> | |||
| <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel"> | |||
| <a-button type="primary" icon="import">导入</a-button> | |||
| </a-upload> | |||
| <!-- 高级查询区域 --> | |||
| <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> | |||
| <a-dropdown v-if="selectedRowKeys.length > 0"> | |||
| <a-menu slot="overlay"> | |||
| <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item> | |||
| </a-menu> | |||
| <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button> | |||
| </a-dropdown> | |||
| </div> | |||
| <!-- table区域-begin --> | |||
| <div> | |||
| <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;"> | |||
| <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项 | |||
| <a style="margin-left: 24px" @click="onClearSelected">清空</a> | |||
| </div> | |||
| <a-table | |||
| ref="table" | |||
| size="middle" | |||
| :scroll="{x:true}" | |||
| bordered | |||
| rowKey="id" | |||
| :columns="columns" | |||
| :dataSource="dataSource" | |||
| :pagination="ipagination" | |||
| :loading="loading" | |||
| :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" | |||
| class="j-table-force-nowrap" | |||
| @change="handleTableChange"> | |||
| <template slot="htmlSlot" slot-scope="text"> | |||
| <div v-html="text"></div> | |||
| </template> | |||
| <template slot="imgSlot" slot-scope="text,record"> | |||
| <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span> | |||
| <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/> | |||
| </template> | |||
| <template slot="fileSlot" slot-scope="text"> | |||
| <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span> | |||
| <a-button | |||
| v-else | |||
| :ghost="true" | |||
| type="primary" | |||
| icon="download" | |||
| size="small" | |||
| @click="downloadFile(text)"> | |||
| 下载 | |||
| </a-button> | |||
| </template> | |||
| <span slot="action" slot-scope="text, record"> | |||
| <a @click="handleEdit(record)">编辑</a> | |||
| <a-divider type="vertical" /> | |||
| <a-dropdown> | |||
| <a class="ant-dropdown-link">更多 <a-icon type="down" /></a> | |||
| <a-menu slot="overlay"> | |||
| <a-menu-item> | |||
| <a @click="handleDetail(record)">详情</a> | |||
| </a-menu-item> | |||
| <a-menu-item> | |||
| <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)"> | |||
| <a>删除</a> | |||
| </a-popconfirm> | |||
| </a-menu-item> | |||
| </a-menu> | |||
| </a-dropdown> | |||
| </span> | |||
| </a-table> | |||
| </div> | |||
| <teambuy-cashout-log-modal ref="modalForm" @ok="modalFormOk"></teambuy-cashout-log-modal> | |||
| </a-card> | |||
| </template> | |||
| <script> | |||
| import '@/assets/less/TableExpand.less' | |||
| import { mixinDevice } from '@/utils/mixin' | |||
| import { JeecgListMixin } from '@/mixins/JeecgListMixin' | |||
| import TeambuyCashoutLogModal from './modules/TeambuyCashoutLogModal' | |||
| export default { | |||
| name: 'TeambuyCashoutLogList', | |||
| mixins:[JeecgListMixin, mixinDevice], | |||
| components: { | |||
| TeambuyCashoutLogModal | |||
| }, | |||
| data () { | |||
| return { | |||
| description: '提现记录表管理页面', | |||
| // 表头 | |||
| columns: [ | |||
| { | |||
| title: '#', | |||
| dataIndex: '', | |||
| key:'rowIndex', | |||
| width:60, | |||
| align:"center", | |||
| customRender:function (t,r,index) { | |||
| return parseInt(index)+1; | |||
| } | |||
| }, | |||
| { | |||
| title:'提现者姓名', | |||
| align:"center", | |||
| dataIndex: 'realName' | |||
| }, | |||
| { | |||
| title:'提现金额', | |||
| align:"center", | |||
| dataIndex: 'amount' | |||
| }, | |||
| { | |||
| title:'到账时间', | |||
| align:"center", | |||
| dataIndex: 'paymentTime' | |||
| }, | |||
| { | |||
| title:'提现状态', | |||
| align:"center", | |||
| dataIndex: 'status' | |||
| }, | |||
| { | |||
| title:'商户单号', | |||
| align:"center", | |||
| dataIndex: 'outBillNo' | |||
| }, | |||
| { | |||
| title:'微信转账单号', | |||
| align:"center", | |||
| dataIndex: 'transferBillNo' | |||
| }, | |||
| { | |||
| title:'领取转账信息参数', | |||
| align:"center", | |||
| dataIndex: 'packageInfo' | |||
| }, | |||
| { | |||
| title:'关联用户id', | |||
| align:"center", | |||
| dataIndex: 'userId' | |||
| }, | |||
| { | |||
| title: '操作', | |||
| dataIndex: 'action', | |||
| align:"center", | |||
| fixed:"right", | |||
| width:147, | |||
| scopedSlots: { customRender: 'action' } | |||
| } | |||
| ], | |||
| url: { | |||
| list: "/teambuyCashoutLog/teambuyCashoutLog/list", | |||
| delete: "/teambuyCashoutLog/teambuyCashoutLog/delete", | |||
| deleteBatch: "/teambuyCashoutLog/teambuyCashoutLog/deleteBatch", | |||
| exportXlsUrl: "/teambuyCashoutLog/teambuyCashoutLog/exportXls", | |||
| importExcelUrl: "teambuyCashoutLog/teambuyCashoutLog/importExcel", | |||
| }, | |||
| dictOptions:{}, | |||
| superFieldList:[], | |||
| } | |||
| }, | |||
| created() { | |||
| this.getSuperFieldList(); | |||
| }, | |||
| computed: { | |||
| importExcelUrl: function(){ | |||
| return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`; | |||
| }, | |||
| }, | |||
| methods: { | |||
| initDictConfig(){ | |||
| }, | |||
| getSuperFieldList(){ | |||
| let fieldList=[]; | |||
| fieldList.push({type:'string',value:'realName',text:'提现者姓名',dictCode:''}) | |||
| fieldList.push({type:'BigDecimal',value:'amount',text:'提现金额',dictCode:''}) | |||
| fieldList.push({type:'datetime',value:'paymentTime',text:'到账时间'}) | |||
| fieldList.push({type:'string',value:'status',text:'提现状态',dictCode:''}) | |||
| fieldList.push({type:'Text',value:'outBillNo',text:'商户单号',dictCode:''}) | |||
| fieldList.push({type:'Text',value:'transferBillNo',text:'微信转账单号',dictCode:''}) | |||
| fieldList.push({type:'Text',value:'packageInfo',text:'领取转账信息参数',dictCode:''}) | |||
| fieldList.push({type:'string',value:'userId',text:'关联用户id',dictCode:''}) | |||
| this.superFieldList = fieldList | |||
| } | |||
| } | |||
| } | |||
| </script> | |||
| <style scoped> | |||
| @import '~@assets/less/common.less'; | |||
| </style> | |||
| @ -0,0 +1,139 @@ | |||
| <template> | |||
| <a-spin :spinning="confirmLoading"> | |||
| <j-form-container :disabled="formDisabled"> | |||
| <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail"> | |||
| <a-row> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="提现者姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="realName"> | |||
| <a-input v-model="model.realName" placeholder="请输入提现者姓名" ></a-input> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="提现金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amount"> | |||
| <a-input-number v-model="model.amount" placeholder="请输入提现金额" style="width: 100%" /> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="到账时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentTime"> | |||
| <j-date placeholder="请选择到账时间" v-model="model.paymentTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" /> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="提现状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status"> | |||
| <a-input v-model="model.status" placeholder="请输入提现状态" ></a-input> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="商户单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outBillNo"> | |||
| <a-input v-model="model.outBillNo" placeholder="请输入商户单号" ></a-input> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="微信转账单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="transferBillNo"> | |||
| <a-input v-model="model.transferBillNo" placeholder="请输入微信转账单号" ></a-input> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="领取转账信息参数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="packageInfo"> | |||
| <a-input v-model="model.packageInfo" placeholder="请输入领取转账信息参数" ></a-input> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| <a-col :span="24"> | |||
| <a-form-model-item label="关联用户id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId"> | |||
| <a-input v-model="model.userId" placeholder="请输入关联用户id" ></a-input> | |||
| </a-form-model-item> | |||
| </a-col> | |||
| </a-row> | |||
| </a-form-model> | |||
| </j-form-container> | |||
| </a-spin> | |||
| </template> | |||
| <script> | |||
| import { httpAction, getAction } from '@/api/manage' | |||
| import { validateDuplicateValue } from '@/utils/util' | |||
| export default { | |||
| name: 'TeambuyCashoutLogForm', | |||
| components: { | |||
| }, | |||
| props: { | |||
| //表单禁用 | |||
| disabled: { | |||
| type: Boolean, | |||
| default: false, | |||
| required: false | |||
| } | |||
| }, | |||
| data () { | |||
| return { | |||
| model:{ | |||
| }, | |||
| labelCol: { | |||
| xs: { span: 24 }, | |||
| sm: { span: 5 }, | |||
| }, | |||
| wrapperCol: { | |||
| xs: { span: 24 }, | |||
| sm: { span: 16 }, | |||
| }, | |||
| confirmLoading: false, | |||
| validatorRules: { | |||
| }, | |||
| url: { | |||
| add: "/teambuyCashoutLog/teambuyCashoutLog/add", | |||
| edit: "/teambuyCashoutLog/teambuyCashoutLog/edit", | |||
| queryById: "/teambuyCashoutLog/teambuyCashoutLog/queryById" | |||
| } | |||
| } | |||
| }, | |||
| computed: { | |||
| formDisabled(){ | |||
| return this.disabled | |||
| }, | |||
| }, | |||
| created () { | |||
| //备份model原始值 | |||
| this.modelDefault = JSON.parse(JSON.stringify(this.model)); | |||
| }, | |||
| methods: { | |||
| add () { | |||
| this.edit(this.modelDefault); | |||
| }, | |||
| edit (record) { | |||
| this.model = Object.assign({}, record); | |||
| this.visible = true; | |||
| }, | |||
| submitForm () { | |||
| const that = this; | |||
| // 触发表单验证 | |||
| this.$refs.form.validate(valid => { | |||
| if (valid) { | |||
| that.confirmLoading = true; | |||
| let httpurl = ''; | |||
| let method = ''; | |||
| if(!this.model.id){ | |||
| httpurl+=this.url.add; | |||
| method = 'post'; | |||
| }else{ | |||
| httpurl+=this.url.edit; | |||
| method = 'put'; | |||
| } | |||
| httpAction(httpurl,this.model,method).then((res)=>{ | |||
| if(res.success){ | |||
| that.$message.success(res.message); | |||
| that.$emit('ok'); | |||
| }else{ | |||
| that.$message.warning(res.message); | |||
| } | |||
| }).finally(() => { | |||
| that.confirmLoading = false; | |||
| }) | |||
| } | |||
| }) | |||
| }, | |||
| } | |||
| } | |||
| </script> | |||
| @ -0,0 +1,84 @@ | |||
| <template> | |||
| <a-drawer | |||
| :title="title" | |||
| :width="width" | |||
| placement="right" | |||
| :closable="false" | |||
| @close="close" | |||
| destroyOnClose | |||
| :visible="visible"> | |||
| <teambuy-cashout-log-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" normal></teambuy-cashout-log-form> | |||
| <div class="drawer-footer"> | |||
| <a-button @click="handleCancel" style="margin-bottom: 0;">关闭</a-button> | |||
| <a-button v-if="!disableSubmit" @click="handleOk" type="primary" style="margin-bottom: 0;">提交</a-button> | |||
| </div> | |||
| </a-drawer> | |||
| </template> | |||
| <script> | |||
| import TeambuyCashoutLogForm from './TeambuyCashoutLogForm' | |||
| export default { | |||
| name: 'TeambuyCashoutLogModal', | |||
| components: { | |||
| TeambuyCashoutLogForm | |||
| }, | |||
| data () { | |||
| return { | |||
| title:"操作", | |||
| width:800, | |||
| visible: false, | |||
| disableSubmit: false | |||
| } | |||
| }, | |||
| methods: { | |||
| add () { | |||
| this.visible=true | |||
| this.$nextTick(()=>{ | |||
| this.$refs.realForm.add(); | |||
| }) | |||
| }, | |||
| edit (record) { | |||
| this.visible=true | |||
| this.$nextTick(()=>{ | |||
| this.$refs.realForm.edit(record); | |||
| }); | |||
| }, | |||
| close () { | |||
| this.$emit('close'); | |||
| this.visible = false; | |||
| }, | |||
| submitCallback(){ | |||
| this.$emit('ok'); | |||
| this.visible = false; | |||
| }, | |||
| handleOk () { | |||
| this.$refs.realForm.submitForm(); | |||
| }, | |||
| handleCancel () { | |||
| this.close() | |||
| } | |||
| } | |||
| } | |||
| </script> | |||
| <style lang="less" scoped> | |||
| /** Button按钮间距 */ | |||
| .ant-btn { | |||
| margin-left: 30px; | |||
| margin-bottom: 30px; | |||
| float: right; | |||
| } | |||
| .drawer-footer{ | |||
| position: absolute; | |||
| bottom: -8px; | |||
| width: 100%; | |||
| border-top: 1px solid #e8e8e8; | |||
| padding: 10px 16px; | |||
| text-align: right; | |||
| left: 0; | |||
| background: #fff; | |||
| border-radius: 0 0 2px 2px; | |||
| } | |||
| </style> | |||
| @ -0,0 +1,60 @@ | |||
| <template> | |||
| <j-modal | |||
| :title="title" | |||
| :width="width" | |||
| :visible="visible" | |||
| switchFullscreen | |||
| @ok="handleOk" | |||
| :okButtonProps="{ class:{'jee-hidden': disableSubmit} }" | |||
| @cancel="handleCancel" | |||
| cancelText="关闭"> | |||
| <teambuy-cashout-log-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit"></teambuy-cashout-log-form> | |||
| </j-modal> | |||
| </template> | |||
| <script> | |||
| import TeambuyCashoutLogForm from './TeambuyCashoutLogForm' | |||
| export default { | |||
| name: 'TeambuyCashoutLogModal', | |||
| components: { | |||
| TeambuyCashoutLogForm | |||
| }, | |||
| data () { | |||
| return { | |||
| title:'', | |||
| width:800, | |||
| visible: false, | |||
| disableSubmit: false | |||
| } | |||
| }, | |||
| methods: { | |||
| add () { | |||
| this.visible=true | |||
| this.$nextTick(()=>{ | |||
| this.$refs.realForm.add(); | |||
| }) | |||
| }, | |||
| edit (record) { | |||
| this.visible=true | |||
| this.$nextTick(()=>{ | |||
| this.$refs.realForm.edit(record); | |||
| }) | |||
| }, | |||
| close () { | |||
| this.$emit('close'); | |||
| this.visible = false; | |||
| }, | |||
| handleOk () { | |||
| this.$refs.realForm.submitForm(); | |||
| }, | |||
| submitCallback(){ | |||
| this.$emit('ok'); | |||
| this.visible = false; | |||
| }, | |||
| handleCancel () { | |||
| this.close() | |||
| } | |||
| } | |||
| } | |||
| </script> | |||
| @ -0,0 +1,61 @@ | |||
| import {defHttp} from '/@/utils/http/axios'; | |||
| import {Modal} from 'ant-design-vue'; | |||
| enum Api { | |||
| list = '/teambuyCashoutLog/teambuyCashoutLog/list', | |||
| save='/teambuyCashoutLog/teambuyCashoutLog/add', | |||
| edit='/teambuyCashoutLog/teambuyCashoutLog/edit', | |||
| deleteOne = '/teambuyCashoutLog/teambuyCashoutLog/delete', | |||
| deleteBatch = '/teambuyCashoutLog/teambuyCashoutLog/deleteBatch', | |||
| importExcel = '/teambuyCashoutLog/teambuyCashoutLog/importExcel', | |||
| exportXls = '/teambuyCashoutLog/teambuyCashoutLog/exportXls', | |||
| } | |||
| /** | |||
| * 导出api | |||
| * @param params | |||
| */ | |||
| export const getExportUrl = Api.exportXls; | |||
| /** | |||
| * 导入api | |||
| */ | |||
| export const getImportUrl = Api.importExcel; | |||
| /** | |||
| * 列表接口 | |||
| * @param params | |||
| */ | |||
| export const list = (params) => | |||
| defHttp.get({url: Api.list, params}); | |||
| /** | |||
| * 删除单个 | |||
| */ | |||
| export const deleteOne = (params,handleSuccess) => { | |||
| return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => { | |||
| handleSuccess(); | |||
| }); | |||
| } | |||
| /** | |||
| * 批量删除 | |||
| * @param params | |||
| */ | |||
| export const batchDelete = (params, handleSuccess) => { | |||
| Modal.confirm({ | |||
| title: '确认删除', | |||
| content: '是否删除选中数据', | |||
| okText: '确认', | |||
| cancelText: '取消', | |||
| onOk: () => { | |||
| return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => { | |||
| handleSuccess(); | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| /** | |||
| * 保存或者更新 | |||
| * @param params | |||
| */ | |||
| export const saveOrUpdate = (params, isUpdate) => { | |||
| let url = isUpdate ? Api.edit : Api.save; | |||
| return defHttp.post({url: url, params}); | |||
| } | |||
| @ -0,0 +1,93 @@ | |||
| import {BasicColumn} from '/@/components/Table'; | |||
| import {FormSchema} from '/@/components/Table'; | |||
| import { rules} from '/@/utils/helper/validator'; | |||
| import { render } from '/@/utils/common/renderUtils'; | |||
| //列表数据 | |||
| export const columns: BasicColumn[] = [ | |||
| { | |||
| title: '提现者姓名', | |||
| align:"center", | |||
| dataIndex: 'realName' | |||
| }, | |||
| { | |||
| title: '提现金额', | |||
| align:"center", | |||
| dataIndex: 'amount' | |||
| }, | |||
| { | |||
| title: '到账时间', | |||
| align:"center", | |||
| dataIndex: 'paymentTime' | |||
| }, | |||
| { | |||
| title: '提现状态', | |||
| align:"center", | |||
| dataIndex: 'status' | |||
| }, | |||
| { | |||
| title: '商户单号', | |||
| align:"center", | |||
| dataIndex: 'outBillNo' | |||
| }, | |||
| { | |||
| title: '微信转账单号', | |||
| align:"center", | |||
| dataIndex: 'transferBillNo' | |||
| }, | |||
| { | |||
| title: '领取转账信息参数', | |||
| align:"center", | |||
| dataIndex: 'packageInfo' | |||
| }, | |||
| { | |||
| title: '关联用户id', | |||
| align:"center", | |||
| dataIndex: 'userId' | |||
| }, | |||
| ]; | |||
| //查询数据 | |||
| export const searchFormSchema: FormSchema[] = [ | |||
| ]; | |||
| //表单数据 | |||
| export const formSchema: FormSchema[] = [ | |||
| { | |||
| label: '提现者姓名', | |||
| field: 'realName', | |||
| component: 'Input', | |||
| }, | |||
| { | |||
| label: '提现金额', | |||
| field: 'amount', | |||
| component: 'InputNumber', | |||
| }, | |||
| { | |||
| label: '到账时间', | |||
| field: 'paymentTime', | |||
| component: 'Input', | |||
| }, | |||
| { | |||
| label: '提现状态', | |||
| field: 'status', | |||
| component: 'Input', | |||
| }, | |||
| { | |||
| label: '商户单号', | |||
| field: 'outBillNo', | |||
| component: 'Input', | |||
| }, | |||
| { | |||
| label: '微信转账单号', | |||
| field: 'transferBillNo', | |||
| component: 'Input', | |||
| }, | |||
| { | |||
| label: '领取转账信息参数', | |||
| field: 'packageInfo', | |||
| component: 'Input', | |||
| }, | |||
| { | |||
| label: '关联用户id', | |||
| field: 'userId', | |||
| component: 'Input', | |||
| }, | |||
| ]; | |||
| @ -0,0 +1,162 @@ | |||
| <template> | |||
| <div> | |||
| <!--引用表格--> | |||
| <BasicTable @register="registerTable" :rowSelection="rowSelection"> | |||
| <!--插槽:table标题--> | |||
| <template #tableTitle> | |||
| <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button> | |||
| <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button> | |||
| <j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button> | |||
| <a-dropdown v-if="checkedKeys.length > 0"> | |||
| <template #overlay> | |||
| <a-menu> | |||
| <a-menu-item key="1" @click="batchHandleDelete"> | |||
| <Icon icon="ant-design:delete-outlined"></Icon> | |||
| 删除 | |||
| </a-menu-item> | |||
| </a-menu> | |||
| </template> | |||
| <a-button>批量操作 | |||
| <Icon icon="mdi:chevron-down"></Icon> | |||
| </a-button> | |||
| </a-dropdown> | |||
| </template> | |||
| <!--操作栏--> | |||
| <template #action="{ record }"> | |||
| <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/> | |||
| </template> | |||
| <!--字段回显插槽--> | |||
| <template #htmlSlot="{text}"> | |||
| <div v-html="text"></div> | |||
| </template> | |||
| <template #fileSlot="{text}"> | |||
| <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span> | |||
| <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button> | |||
| </template> | |||
| </BasicTable> | |||
| <!-- 表单区域 --> | |||
| <TeambuyCashoutLogModal @register="registerModal" @success="handleSuccess"></TeambuyCashoutLogModal> | |||
| </div> | |||
| </template> | |||
| <script lang="ts" name="teambuyCashoutLog-teambuyCashoutLog" setup> | |||
| import {ref, computed, unref} from 'vue'; | |||
| import {BasicTable, useTable, TableAction} from '/@/components/Table'; | |||
| import {useModal} from '/@/components/Modal'; | |||
| import { useListPage } from '/@/hooks/system/useListPage' | |||
| import TeambuyCashoutLogModal from './components/TeambuyCashoutLogModal.vue' | |||
| import {columns, searchFormSchema} from './teambuyCashoutLog.data'; | |||
| import {list, deleteOne, batchDelete, getImportUrl,getExportUrl} from './teambuyCashoutLog.api'; | |||
| const checkedKeys = ref<Array<string | number>>([]); | |||
| //注册model | |||
| const [registerModal, {openModal}] = useModal(); | |||
| //注册table数据 | |||
| const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({ | |||
| tableProps:{ | |||
| title: '提现记录表', | |||
| api: list, | |||
| columns, | |||
| canResize:false, | |||
| formConfig: { | |||
| labelWidth: 120, | |||
| schemas: searchFormSchema, | |||
| autoSubmitOnEnter:true, | |||
| showAdvancedButton:true, | |||
| fieldMapToTime: [ | |||
| ], | |||
| }, | |||
| actionColumn: { | |||
| width: 120, | |||
| }, | |||
| }, | |||
| exportConfig: { | |||
| name:"提现记录表", | |||
| url: getExportUrl, | |||
| }, | |||
| importConfig: { | |||
| url: getImportUrl | |||
| }, | |||
| }) | |||
| const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext | |||
| /** | |||
| * 新增事件 | |||
| */ | |||
| function handleAdd() { | |||
| openModal(true, { | |||
| isUpdate: false, | |||
| showFooter: true, | |||
| }); | |||
| } | |||
| /** | |||
| * 编辑事件 | |||
| */ | |||
| function handleEdit(record: Recordable) { | |||
| openModal(true, { | |||
| record, | |||
| isUpdate: true, | |||
| showFooter: true, | |||
| }); | |||
| } | |||
| /** | |||
| * 详情 | |||
| */ | |||
| function handleDetail(record: Recordable) { | |||
| openModal(true, { | |||
| record, | |||
| isUpdate: true, | |||
| showFooter: false, | |||
| }); | |||
| } | |||
| /** | |||
| * 删除事件 | |||
| */ | |||
| async function handleDelete(record) { | |||
| await deleteOne({id: record.id}, reload); | |||
| } | |||
| /** | |||
| * 批量删除事件 | |||
| */ | |||
| async function batchHandleDelete() { | |||
| await batchDelete({ids: checkedKeys.value}, reload); | |||
| } | |||
| /** | |||
| * 成功回调 | |||
| */ | |||
| function handleSuccess() { | |||
| reload(); | |||
| } | |||
| /** | |||
| * 操作栏 | |||
| */ | |||
| function getTableAction(record){ | |||
| return [ | |||
| { | |||
| label: '编辑', | |||
| onClick: handleEdit.bind(null, record), | |||
| } | |||
| ] | |||
| } | |||
| /** | |||
| * 下拉操作栏 | |||
| */ | |||
| function getDropDownAction(record){ | |||
| return [ | |||
| { | |||
| label: '详情', | |||
| onClick: handleDetail.bind(null, record), | |||
| }, { | |||
| label: '删除', | |||
| popConfirm: { | |||
| title: '是否确认删除', | |||
| confirm: handleDelete.bind(null, record), | |||
| } | |||
| } | |||
| ] | |||
| } | |||
| </script> | |||
| <style scoped> | |||
| </style> | |||
| @ -0,0 +1,58 @@ | |||
| <template> | |||
| <BasicModal v-bind="$attrs" @register="registerModal" :title="title" @ok="handleSubmit"> | |||
| <BasicForm @register="registerForm"/> | |||
| </BasicModal> | |||
| </template> | |||
| <script lang="ts" setup> | |||
| import {ref, computed, unref} from 'vue'; | |||
| import {BasicModal, useModalInner} from '/@/components/Modal'; | |||
| import {BasicForm, useForm} from '/@/components/Form/index'; | |||
| import {formSchema} from '../teambuyCashoutLog.data'; | |||
| import {saveOrUpdate} from '../teambuyCashoutLog.api'; | |||
| // Emits声明 | |||
| const emit = defineEmits(['register','success']); | |||
| const isUpdate = ref(true); | |||
| //表单配置 | |||
| const [registerForm, {setProps,resetFields, setFieldsValue, validate}] = useForm({ | |||
| labelWidth: 150, | |||
| schemas: formSchema, | |||
| showActionButtonGroup: false, | |||
| }); | |||
| //表单赋值 | |||
| const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => { | |||
| //重置表单 | |||
| await resetFields(); | |||
| setModalProps({confirmLoading: false,showCancelBtn:!!data?.showFooter,showOkBtn:!!data?.showFooter}); | |||
| isUpdate.value = !!data?.isUpdate; | |||
| if (unref(isUpdate)) { | |||
| //表单赋值 | |||
| await setFieldsValue({ | |||
| ...data.record, | |||
| }); | |||
| } | |||
| // 隐藏底部时禁用整个表单 | |||
| setProps({ disabled: !data?.showFooter }) | |||
| }); | |||
| //设置标题 | |||
| const title = computed(() => (!unref(isUpdate) ? '新增' : '编辑')); | |||
| //表单提交事件 | |||
| async function handleSubmit(v) { | |||
| try { | |||
| let values = await validate(); | |||
| setModalProps({confirmLoading: true}); | |||
| //提交表单 | |||
| await saveOrUpdate(values, isUpdate.value); | |||
| //关闭弹窗 | |||
| closeModal(); | |||
| //刷新列表 | |||
| emit('success'); | |||
| } finally { | |||
| setModalProps({confirmLoading: false}); | |||
| } | |||
| } | |||
| </script> | |||
| <style lang="less" scoped> | |||
| </style> | |||
| @ -0,0 +1,318 @@ | |||
| package org.jeecg.modules.transfer; | |||
| import com.google.gson.annotations.SerializedName; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import okhttp3.*; | |||
| import java.io.IOException; | |||
| import java.io.UncheckedIOException; | |||
| import java.security.PrivateKey; | |||
| import java.security.PublicKey; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| /** | |||
| * 发起转账 | |||
| */ | |||
| @Slf4j | |||
| public class TransferToUser { | |||
| private final String mchid; | |||
| private final String certificateSerialNo; | |||
| private final PrivateKey privateKey; | |||
| private final String wechatPayPublicKeyId; | |||
| private final PublicKey wechatPayPublicKey; | |||
| public TransferToUser(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { | |||
| this.mchid = mchid; | |||
| this.certificateSerialNo = certificateSerialNo; | |||
| this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); | |||
| this.wechatPayPublicKeyId = wechatPayPublicKeyId; | |||
| this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); | |||
| } | |||
| // /** | |||
| // * 微信提现基础参数 | |||
| // * @return | |||
| // */ | |||
| // public static Map getMap(){ | |||
| // Map<String, Object> map = new HashedMap();//转账接口所需参数 | |||
| // map.put("host", "https://api.mch.weixin.qq.com");//请求地址 | |||
| // map.put("method", "POST");//请求类型 | |||
| // map.put("path", "/v3/fund-app/mch-transfer/transfer-bills");//提现接口 | |||
| // map.put("notifyUrl", "https://www.yurangongfang.com/massage-admin/massage/cash/cashoutNotify/");//回调接口 | |||
| // | |||
| //// //微信商户参数 | |||
| //// map.put("appid", "wx77ba4c7131677a74");//小程序appid | |||
| //// map.put("mchid", "1712378227");//商户号 | |||
| //// map.put("certiticateSerialNo", "33E9FE8076531A7C7AD401DC34E053DBD7C28E22");//商户序列号 | |||
| //// map.put("privateKeyFilePath", "jeecg-boot-module-system/src/main/resources/apiclient_key.pem");//商户私钥证书 | |||
| //// map.put("wechatPayPublicKeyId", "PUB_KEY_ID_0117123782272025033100396400002931");//商户公钥id | |||
| //// map.put("wechatPayPublicKeyFilePath", "jeecg-boot-module-system/src/main/resources/pub_key.pem");//商户公钥证书 | |||
| //// map.put("transferSceneId", "1005");//商户转账场景ID 1005-佣金报酬 | |||
| //// map.put("transferRemark", "佣金报酬");//商户转账场景ID 1005-佣金报酬 | |||
| //// map.put("userRecvPerception", "劳务报酬");//商户转账场景ID 1005-佣金报酬 | |||
| // | |||
| // //微信商户参数(瑶都万能墙测试参数) | |||
| // map.put("appid", "wxa4d29e67e8a58d38");//小程序appid | |||
| // map.put("mchid", "1673516176");//商户号 | |||
| // map.put("certiticateSerialNo", "246ED77A7F882A59FD79993D09FDD2BA9A868FFE");//商户序列号 | |||
| // map.put("privateKeyFilePath", "jeecg-boot-module-system/src/main/resources/apiclient_key_yaodu.pem");//商户私钥证书 | |||
| // map.put("wechatPayPublicKeyId", "PUB_KEY_ID_0116735161762025040100448900000949");//商户公钥id | |||
| // map.put("wechatPayPublicKeyFilePath", "jeecg-boot-module-system/src/main/resources/pub_key_yaodu.pem");//商户公钥证书 | |||
| // map.put("transferSceneId", "1005");//商户转账场景ID 1005-佣金报酬 | |||
| // map.put("transferRemark", "佣金报酬");//商户转账场景ID 1005-佣金报酬 | |||
| // map.put("userRecvPerception", "劳务报酬");//商户转账场景ID 1005-佣金报酬 | |||
| // | |||
| // | |||
| // //变化的用户信息参数 | |||
| //// map.put("openid", "oFzrW4migndUepy7zYgYO2YoZ5to");//用户openid | |||
| //// map.put("userName", "用户真实姓名");//用户真实姓名 | |||
| // map.put("transferAmount", 100L);//提现金额, 单位为“分” | |||
| // String idStr = "H" + IdWorker.getIdStr(); | |||
| // map.put("outBillNo", idStr);//商户单号 | |||
| // | |||
| // | |||
| // //转账场景报备信息,ransfer_scene_report_infos为数组类型参数,在现金营销的转账场景下需固定传两条明细,每条“转账场景报备信息明细”包含info_type、info_content两个参数。 | |||
| // map.put("infoType1","岗位类型"); | |||
| // map.put("infoContent1","外卖员"); | |||
| // map.put("infoType2","报酬说明"); | |||
| // map.put("infoContent2","高温补贴"); | |||
| // | |||
| // return map; | |||
| // | |||
| // } | |||
| // | |||
| // public static void main(String[] args) { | |||
| // // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 | |||
| // | |||
| // Map map = getMap(); | |||
| // TransferToUser client = new TransferToUser( | |||
| // map.get("mchid").toString(), // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 | |||
| // map.get("certiticateSerialNo").toString(), // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 | |||
| // map.get("privateKeyFilePath").toString(), // 商户API证书私钥文件路径,本地文件路径 | |||
| // map.get("wechatPayPublicKeyId").toString(), // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 | |||
| // map.get("wechatPayPublicKeyFilePath").toString() // 微信支付公钥文件路径,本地文件路径 | |||
| // ); | |||
| // | |||
| // TransferToUserRequest request = new TransferToUserRequest(); | |||
| // request.appid = map.get("appid").toString(); | |||
| // String idStr = "H" + IdWorker.getIdStr(); | |||
| // request.outBillNo = idStr; | |||
| // request.transferSceneId = map.get("transferSceneId").toString(); | |||
| // request.openid = map.get("openid").toString(); | |||
| // request.userName = client.encrypt(map.get("userName").toString()); | |||
| // request.transferAmount = 100L; | |||
| // request.transferRemark = map.get("transferRemark").toString(); | |||
| // request.notifyUrl = map.get("notifyUrl").toString(); | |||
| // request.userRecvPerception = map.get("userRecvPerception").toString(); | |||
| // request.transferSceneReportInfos = new ArrayList<>(); | |||
| // { | |||
| // TransferSceneReportInfo item0 = new TransferSceneReportInfo(); | |||
| // item0.infoType = map.get("infoType1").toString(); | |||
| // item0.infoContent = map.get("infoContent1").toString(); | |||
| // request.transferSceneReportInfos.add(item0); | |||
| // TransferSceneReportInfo item1 = new TransferSceneReportInfo(); | |||
| // item1.infoType = map.get("infoType2").toString(); | |||
| // item1.infoContent = map.get("infoContent2").toString(); | |||
| // request.transferSceneReportInfos.add(item1); | |||
| // }; | |||
| // try { | |||
| // TransferToUserResponse response = client.run(request, map); | |||
| // // TODO: 请求成功,继续业务逻辑 | |||
| // System.out.println(response); | |||
| // } catch (WXPayUtility.ApiException e) { | |||
| // // TODO: 请求失败,根据状态码执行不同的逻辑 | |||
| // e.printStackTrace(); | |||
| // } | |||
| // } | |||
| // | |||
| // | |||
| // public TransferToUserResponse run(Map map){ | |||
| // TransferToUser client = new TransferToUser( | |||
| // map.get("mchid").toString(), // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 | |||
| // map.get("certiticateSerialNo").toString(), // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 | |||
| // map.get("privateKeyFilePath").toString(), // 商户API证书私钥文件路径,本地文件路径 | |||
| // map.get("wechatPayPublicKeyId").toString(), // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 | |||
| // map.get("wechatPayPublicKeyFilePath").toString() // 微信支付公钥文件路径,本地文件路径 | |||
| // ); | |||
| // | |||
| // TransferToUserRequest request = new TransferToUserRequest(); | |||
| // | |||
| // | |||
| // request.appid = map.get("appid").toString(); | |||
| // request.outBillNo = map.get("outBillNo").toString(); | |||
| // request.transferSceneId = map.get("transferSceneId").toString(); | |||
| // request.openid = map.get("openid").toString(); | |||
| // request.userName = client.encrypt(map.get("userName").toString()); | |||
| // request.transferAmount = 100L; | |||
| // request.transferRemark = map.get("transferRemark").toString(); | |||
| // request.notifyUrl = map.get("notifyUrl").toString(); | |||
| // request.userRecvPerception = map.get("userRecvPerception").toString(); | |||
| // request.transferSceneReportInfos = new ArrayList<>(); | |||
| // { | |||
| // TransferSceneReportInfo item0 = new TransferSceneReportInfo(); | |||
| // item0.infoType = map.get("infoType1").toString(); | |||
| // item0.infoContent = map.get("infoContent1").toString(); | |||
| // request.transferSceneReportInfos.add(item0); | |||
| // TransferSceneReportInfo item1 = new TransferSceneReportInfo(); | |||
| // item1.infoType = map.get("infoType2").toString(); | |||
| // item1.infoContent = map.get("infoContent2").toString(); | |||
| // request.transferSceneReportInfos.add(item1); | |||
| // }; | |||
| // try { | |||
| // TransferToUserResponse response = client.run(request, map); | |||
| // // TODO: 请求成功,继续业务逻辑 | |||
| // log.info("提现发起成功,outBillNo:"+response.outBillNo + ",transferBillNo:" +response.transferBillNo + ",state:" +response.state); | |||
| // //转账结果 | |||
| // switch (response.state){ | |||
| // case ACCEPTED: | |||
| // log.info("转账已受理"); | |||
| // break; | |||
| // case PROCESSING: | |||
| // log.info("转账锁定资金中。如果一直停留在该状态,建议检查账户余额是否足够,如余额不足,可充值后再原单重试"); | |||
| // break; | |||
| // case WAIT_USER_CONFIRM: | |||
| // log.info("待收款用户确认,可拉起微信收款确认页面进行收款确认"); | |||
| // break; | |||
| // case TRANSFERING: | |||
| // log.info("转账中,可拉起微信收款确认页面再次重试确认收款"); | |||
| // break; | |||
| // case SUCCESS: | |||
| // log.info("转账成功"); | |||
| // break; | |||
| // case FAIL: | |||
| // log.info("转账失败"); | |||
| // break; | |||
| // case CANCELING: | |||
| // log.info("商户撤销请求受理成功,该笔转账正在撤销中"); | |||
| // break; | |||
| // case CANCELLED: | |||
| // log.info("转账撤销完成"); | |||
| // break; | |||
| // } | |||
| // log.info("提现发起完成"); | |||
| // return response; | |||
| // } catch (WXPayUtility.ApiException e) { | |||
| // // TODO: 请求失败,根据状态码执行不同的逻辑 | |||
| // log.info("提现发起失败"); | |||
| // e.printStackTrace(); | |||
| // return null; | |||
| // } | |||
| // } | |||
| public TransferToUserResponse run(TransferToUserRequest request, Map map) { | |||
| String uri = map.get("path").toString(); | |||
| String host = map.get("host").toString(); | |||
| String method = map.get("method").toString(); | |||
| String reqBody = WXPayUtility.toJson(request); | |||
| Request.Builder reqBuilder = new Request.Builder().url(host + uri); | |||
| reqBuilder.addHeader("Accept", "application/json"); | |||
| reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); | |||
| reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, method, uri, reqBody)); | |||
| reqBuilder.addHeader("Content-Type", "application/json"); | |||
| RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); | |||
| reqBuilder.method(method, requestBody); | |||
| Request httpRequest = reqBuilder.build(); | |||
| // 发送HTTP请求 | |||
| OkHttpClient client = new OkHttpClient.Builder().build(); | |||
| try (Response httpResponse = client.newCall(httpRequest).execute()) { | |||
| String respBody = WXPayUtility.extractBody(httpResponse); | |||
| if (httpResponse.code() >= 200 && httpResponse.code() < 300) { | |||
| // 2XX 成功,验证应答签名 | |||
| WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, | |||
| httpResponse.headers(), respBody); | |||
| // 从HTTP应答报文构建返回数据 | |||
| return WXPayUtility.fromJson(respBody, TransferToUserResponse.class); | |||
| } else { | |||
| throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); | |||
| } | |||
| } catch (IOException e) { | |||
| throw new UncheckedIOException("Sending request to " + uri + " failed.", e); | |||
| } | |||
| } | |||
| public String encrypt(String plainText) { | |||
| return WXPayUtility.encrypt(this.wechatPayPublicKey, plainText); | |||
| } | |||
| public static class TransferToUserResponse { | |||
| @SerializedName("out_bill_no") | |||
| public String outBillNo; | |||
| @SerializedName("transfer_bill_no") | |||
| public String transferBillNo; | |||
| @SerializedName("create_time") | |||
| public String createTime; | |||
| @SerializedName("state") | |||
| public TransferBillStatus state; | |||
| @SerializedName("package_info") | |||
| public String packageInfo; | |||
| } | |||
| public enum TransferBillStatus { | |||
| @SerializedName("ACCEPTED") | |||
| ACCEPTED, | |||
| @SerializedName("PROCESSING") | |||
| PROCESSING, | |||
| @SerializedName("WAIT_USER_CONFIRM") | |||
| WAIT_USER_CONFIRM, | |||
| @SerializedName("TRANSFERING") | |||
| TRANSFERING, | |||
| @SerializedName("SUCCESS") | |||
| SUCCESS, | |||
| @SerializedName("FAIL") | |||
| FAIL, | |||
| @SerializedName("CANCELING") | |||
| CANCELING, | |||
| @SerializedName("CANCELLED") | |||
| CANCELLED | |||
| } | |||
| public static class TransferSceneReportInfo { | |||
| @SerializedName("info_type") | |||
| public String infoType; | |||
| @SerializedName("info_content") | |||
| public String infoContent; | |||
| } | |||
| public static class TransferToUserRequest { | |||
| @SerializedName("appid") | |||
| public String appid; | |||
| @SerializedName("out_bill_no") | |||
| public String outBillNo; | |||
| @SerializedName("transfer_scene_id") | |||
| public String transferSceneId; | |||
| @SerializedName("openid") | |||
| public String openid; | |||
| @SerializedName("user_name") | |||
| public String userName; | |||
| @SerializedName("transfer_amount") | |||
| public Long transferAmount; | |||
| @SerializedName("transfer_remark") | |||
| public String transferRemark; | |||
| @SerializedName("notify_url") | |||
| public String notifyUrl; | |||
| @SerializedName("user_recv_perception") | |||
| public String userRecvPerception; | |||
| @SerializedName("transfer_scene_report_infos") | |||
| public List<TransferSceneReportInfo> transferSceneReportInfos; | |||
| } | |||
| } | |||
| @ -0,0 +1,381 @@ | |||
| package org.jeecg.modules.transfer; | |||
| import com.google.gson.*; | |||
| import com.google.gson.annotations.Expose; | |||
| import okhttp3.Headers; | |||
| import okhttp3.Response; | |||
| import okio.BufferedSource; | |||
| import javax.crypto.BadPaddingException; | |||
| import javax.crypto.Cipher; | |||
| import javax.crypto.IllegalBlockSizeException; | |||
| import javax.crypto.NoSuchPaddingException; | |||
| import java.io.IOException; | |||
| import java.io.UncheckedIOException; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.net.URLEncoder; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.nio.file.Files; | |||
| import java.nio.file.Paths; | |||
| import java.security.*; | |||
| import java.security.spec.InvalidKeySpecException; | |||
| import java.security.spec.PKCS8EncodedKeySpec; | |||
| import java.security.spec.X509EncodedKeySpec; | |||
| import java.time.DateTimeException; | |||
| import java.time.Duration; | |||
| import java.time.Instant; | |||
| import java.util.Base64; | |||
| import java.util.Map; | |||
| import java.util.Objects; | |||
| public class WXPayUtility { | |||
| private static final Gson gson = new GsonBuilder() | |||
| .disableHtmlEscaping() | |||
| .addSerializationExclusionStrategy(new ExclusionStrategy() { | |||
| @Override | |||
| public boolean shouldSkipField(FieldAttributes fieldAttributes) { | |||
| final Expose expose = fieldAttributes.getAnnotation(Expose.class); | |||
| return expose != null && !expose.serialize(); | |||
| } | |||
| @Override | |||
| public boolean shouldSkipClass(Class<?> aClass) { | |||
| return false; | |||
| } | |||
| }) | |||
| .addDeserializationExclusionStrategy(new ExclusionStrategy() { | |||
| @Override | |||
| public boolean shouldSkipField(FieldAttributes fieldAttributes) { | |||
| final Expose expose = fieldAttributes.getAnnotation(Expose.class); | |||
| return expose != null && !expose.deserialize(); | |||
| } | |||
| @Override | |||
| public boolean shouldSkipClass(Class<?> aClass) { | |||
| return false; | |||
| } | |||
| }) | |||
| .create(); | |||
| private static final char[] SYMBOLS = | |||
| "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray(); | |||
| private static final SecureRandom random = new SecureRandom(); | |||
| /** | |||
| * 将 Object 转换为 JSON 字符串 | |||
| */ | |||
| public static String toJson(Object object) { | |||
| return gson.toJson(object); | |||
| } | |||
| /** | |||
| * 将 JSON 字符串解析为特定类型的实例 | |||
| */ | |||
| public static <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException { | |||
| return gson.fromJson(json, classOfT); | |||
| } | |||
| /** | |||
| * 从公私钥文件路径中读取文件内容 | |||
| * | |||
| * @param keyPath 文件路径 | |||
| * @return 文件内容 | |||
| */ | |||
| private static String readKeyStringFromPath(String keyPath) { | |||
| try { | |||
| return new String(Files.readAllBytes(Paths.get(keyPath)), StandardCharsets.UTF_8); | |||
| } catch (IOException e) { | |||
| throw new UncheckedIOException(e); | |||
| } | |||
| } | |||
| /** | |||
| * 读取 PKCS#8 格式的私钥字符串并加载为私钥对象 | |||
| * | |||
| * @param keyString 私钥文件内容,以 -----BEGIN PRIVATE KEY----- 开头 | |||
| * @return PrivateKey 对象 | |||
| */ | |||
| public static PrivateKey loadPrivateKeyFromString(String keyString) { | |||
| try { | |||
| keyString = keyString.replace("-----BEGIN PRIVATE KEY-----", "") | |||
| .replace("-----END PRIVATE KEY-----", "") | |||
| .replaceAll("\\s+", ""); | |||
| return KeyFactory.getInstance("RSA").generatePrivate( | |||
| new PKCS8EncodedKeySpec(Base64.getDecoder().decode(keyString))); | |||
| } catch (NoSuchAlgorithmException e) { | |||
| throw new UnsupportedOperationException(e); | |||
| } catch (InvalidKeySpecException e) { | |||
| throw new IllegalArgumentException(e); | |||
| } | |||
| } | |||
| /** | |||
| * 从 PKCS#8 格式的私钥文件中加载私钥 | |||
| * | |||
| * @param keyPath 私钥文件路径 | |||
| * @return PrivateKey 对象 | |||
| */ | |||
| public static PrivateKey loadPrivateKeyFromPath(String keyPath) { | |||
| return loadPrivateKeyFromString(readKeyStringFromPath(keyPath)); | |||
| } | |||
| /** | |||
| * 读取 PKCS#8 格式的公钥字符串并加载为公钥对象 | |||
| * | |||
| * @param keyString 公钥文件内容,以 -----BEGIN PUBLIC KEY----- 开头 | |||
| * @return PublicKey 对象 | |||
| */ | |||
| public static PublicKey loadPublicKeyFromString(String keyString) { | |||
| try { | |||
| keyString = keyString.replace("-----BEGIN PUBLIC KEY-----", "") | |||
| .replace("-----END PUBLIC KEY-----", "") | |||
| .replaceAll("\\s+", ""); | |||
| return KeyFactory.getInstance("RSA").generatePublic( | |||
| new X509EncodedKeySpec(Base64.getDecoder().decode(keyString))); | |||
| } catch (NoSuchAlgorithmException e) { | |||
| throw new UnsupportedOperationException(e); | |||
| } catch (InvalidKeySpecException e) { | |||
| throw new IllegalArgumentException(e); | |||
| } | |||
| } | |||
| /** | |||
| * 从 PKCS#8 格式的公钥文件中加载公钥 | |||
| * | |||
| * @param keyPath 公钥文件路径 | |||
| * @return PublicKey 对象 | |||
| */ | |||
| public static PublicKey loadPublicKeyFromPath(String keyPath) { | |||
| return loadPublicKeyFromString(readKeyStringFromPath(keyPath)); | |||
| } | |||
| /** | |||
| * 创建指定长度的随机字符串,字符集为[0-9a-zA-Z],可用于安全相关用途 | |||
| */ | |||
| public static String createNonce(int length) { | |||
| char[] buf = new char[length]; | |||
| for (int i = 0; i < length; ++i) { | |||
| buf[i] = SYMBOLS[random.nextInt(SYMBOLS.length)]; | |||
| } | |||
| return new String(buf); | |||
| } | |||
| /** | |||
| * 使用公钥按照 RSA_PKCS1_OAEP_PADDING 算法进行加密 | |||
| * | |||
| * @param publicKey 加密用公钥对象 | |||
| * @param plaintext 待加密明文 | |||
| * @return 加密后密文 | |||
| */ | |||
| public static String encrypt(PublicKey publicKey, String plaintext) { | |||
| final String transformation = "RSA/ECB/OAEPWithSHA-1AndMGF1Padding"; | |||
| try { | |||
| Cipher cipher = Cipher.getInstance(transformation); | |||
| cipher.init(Cipher.ENCRYPT_MODE, publicKey); | |||
| return Base64.getEncoder().encodeToString(cipher.doFinal(plaintext.getBytes(StandardCharsets.UTF_8))); | |||
| } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { | |||
| throw new IllegalArgumentException("The current Java environment does not support " + transformation, e); | |||
| } catch (InvalidKeyException e) { | |||
| throw new IllegalArgumentException("RSA encryption using an illegal publicKey", e); | |||
| } catch (BadPaddingException | IllegalBlockSizeException e) { | |||
| throw new IllegalArgumentException("Plaintext is too long", e); | |||
| } | |||
| } | |||
| /** | |||
| * 使用私钥按照指定算法进行签名 | |||
| * | |||
| * @param message 待签名串 | |||
| * @param algorithm 签名算法,如 SHA256withRSA | |||
| * @param privateKey 签名用私钥对象 | |||
| * @return 签名结果 | |||
| */ | |||
| public static String sign(String message, String algorithm, PrivateKey privateKey) { | |||
| byte[] sign; | |||
| try { | |||
| Signature signature = Signature.getInstance(algorithm); | |||
| signature.initSign(privateKey); | |||
| signature.update(message.getBytes(StandardCharsets.UTF_8)); | |||
| sign = signature.sign(); | |||
| } catch (NoSuchAlgorithmException e) { | |||
| throw new UnsupportedOperationException("The current Java environment does not support " + algorithm, e); | |||
| } catch (InvalidKeyException e) { | |||
| throw new IllegalArgumentException(algorithm + " signature uses an illegal privateKey.", e); | |||
| } catch (SignatureException e) { | |||
| throw new RuntimeException("An error occurred during the sign process.", e); | |||
| } | |||
| return Base64.getEncoder().encodeToString(sign); | |||
| } | |||
| /** | |||
| * 使用公钥按照特定算法验证签名 | |||
| * | |||
| * @param message 待签名串 | |||
| * @param signature 待验证的签名内容 | |||
| * @param algorithm 签名算法,如:SHA256withRSA | |||
| * @param publicKey 验签用公钥对象 | |||
| * @return 签名验证是否通过 | |||
| */ | |||
| public static boolean verify(String message, String signature, String algorithm, | |||
| PublicKey publicKey) { | |||
| try { | |||
| Signature sign = Signature.getInstance(algorithm); | |||
| sign.initVerify(publicKey); | |||
| sign.update(message.getBytes(StandardCharsets.UTF_8)); | |||
| return sign.verify(Base64.getDecoder().decode(signature)); | |||
| } catch (SignatureException e) { | |||
| return false; | |||
| } catch (InvalidKeyException e) { | |||
| throw new IllegalArgumentException("verify uses an illegal publickey.", e); | |||
| } catch (NoSuchAlgorithmException e) { | |||
| throw new UnsupportedOperationException("The current Java environment does not support" + algorithm, e); | |||
| } | |||
| } | |||
| /** | |||
| * 根据微信支付APIv3请求签名规则构造 Authorization 签名 | |||
| * | |||
| * @param mchid 商户号 | |||
| * @param certificateSerialNo 商户API证书序列号 | |||
| * @param privateKey 商户API证书私钥 | |||
| * @param method 请求接口的HTTP方法,请使用全大写表述,如 GET、POST、PUT、DELETE | |||
| * @param uri 请求接口的URL | |||
| * @param body 请求接口的Body | |||
| * @return 构造好的微信支付APIv3 Authorization 头 | |||
| */ | |||
| public static String buildAuthorization(String mchid, String certificateSerialNo, | |||
| PrivateKey privateKey, | |||
| String method, String uri, String body) { | |||
| String nonce = createNonce(32); | |||
| long timestamp = Instant.now().getEpochSecond(); | |||
| String message = String.format("%s\n%s\n%d\n%s\n%s\n", method, uri, timestamp, nonce, | |||
| body == null ? "" : body); | |||
| String signature = sign(message, "SHA256withRSA", privateKey); | |||
| return String.format( | |||
| "WECHATPAY2-SHA256-RSA2048 mchid=\"%s\",nonce_str=\"%s\",signature=\"%s\"," + | |||
| "timestamp=\"%d\",serial_no=\"%s\"", | |||
| mchid, nonce, signature, timestamp, certificateSerialNo); | |||
| } | |||
| /** | |||
| * 对参数进行 URL 编码 | |||
| * | |||
| * @param content 参数内容 | |||
| * @return 编码后的内容 | |||
| */ | |||
| public static String urlEncode(String content) { | |||
| try { | |||
| return URLEncoder.encode(content, StandardCharsets.UTF_8.name()); | |||
| } catch (UnsupportedEncodingException e) { | |||
| throw new RuntimeException(e); | |||
| } | |||
| } | |||
| /** | |||
| * 对参数Map进行 URL 编码,生成 QueryString | |||
| * | |||
| * @param params Query参数Map | |||
| * @return QueryString | |||
| */ | |||
| public static String urlEncode(Map<String, Object> params) { | |||
| if (params == null || params.isEmpty()) { | |||
| return ""; | |||
| } | |||
| int index = 0; | |||
| StringBuilder result = new StringBuilder(); | |||
| for (Map.Entry<String, Object> entry : params.entrySet()) { | |||
| result.append(entry.getKey()) | |||
| .append("=") | |||
| .append(urlEncode(entry.getValue().toString())); | |||
| index++; | |||
| if (index < params.size()) { | |||
| result.append("&"); | |||
| } | |||
| } | |||
| return result.toString(); | |||
| } | |||
| /** | |||
| * 从应答中提取 Body | |||
| * | |||
| * @param response HTTP 请求应答对象 | |||
| * @return 应答中的Body内容,Body为空时返回空字符串 | |||
| */ | |||
| public static String extractBody(Response response) { | |||
| if (response.body() == null) { | |||
| return ""; | |||
| } | |||
| try { | |||
| BufferedSource source = response.body().source(); | |||
| return source.readUtf8(); | |||
| } catch (IOException e) { | |||
| throw new RuntimeException(String.format("An error occurred during reading response body. Status: %d", response.code()), e); | |||
| } | |||
| } | |||
| /** | |||
| * 根据微信支付APIv3应答验签规则对应答签名进行验证,验证不通过时抛出异常 | |||
| * | |||
| * @param wechatpayPublicKeyId 微信支付公钥ID | |||
| * @param wechatpayPublicKey 微信支付公钥对象 | |||
| * @param headers 微信支付应答 Header 列表 | |||
| * @param body 微信支付应答 Body | |||
| */ | |||
| public static void validateResponse(String wechatpayPublicKeyId, PublicKey wechatpayPublicKey, | |||
| Headers headers, | |||
| String body) { | |||
| String timestamp = headers.get("Wechatpay-Timestamp"); | |||
| try { | |||
| Instant responseTime = Instant.ofEpochSecond(Long.parseLong(timestamp)); | |||
| // 拒绝过期请求 | |||
| if (Duration.between(responseTime, Instant.now()).abs().toMinutes() >= 5) { | |||
| throw new IllegalArgumentException( | |||
| String.format("Validate http response,timestamp[%s] of httpResponse is expires, " | |||
| + "request-id[%s]", | |||
| timestamp, headers.get("Request-ID"))); | |||
| } | |||
| } catch (DateTimeException | NumberFormatException e) { | |||
| throw new IllegalArgumentException( | |||
| String.format("Validate http response,timestamp[%s] of httpResponse is invalid, " + | |||
| "request-id[%s]", timestamp, | |||
| headers.get("Request-ID"))); | |||
| } | |||
| String message = String.format("%s\n%s\n%s\n", timestamp, headers.get("Wechatpay-Nonce"), | |||
| body == null ? "" : body); | |||
| String serialNumber = headers.get("Wechatpay-Serial"); | |||
| if (!Objects.equals(serialNumber, wechatpayPublicKeyId)) { | |||
| throw new IllegalArgumentException( | |||
| String.format("Invalid Wechatpay-Serial, Local: %s, Remote: %s", wechatpayPublicKeyId, | |||
| serialNumber)); | |||
| } | |||
| String signature = headers.get("Wechatpay-Signature"); | |||
| boolean success = verify(message, signature, "SHA256withRSA", wechatpayPublicKey); | |||
| if (!success) { | |||
| throw new IllegalArgumentException( | |||
| String.format("Validate response failed,the WechatPay signature is incorrect.%n" | |||
| + "Request-ID[%s]\tresponseHeader[%s]\tresponseBody[%.1024s]", | |||
| headers.get("Request-ID"), headers, body)); | |||
| } | |||
| } | |||
| /** | |||
| * 微信支付API错误异常,发送HTTP请求成功,但返回状态码不是 2XX 时抛出本异常 | |||
| */ | |||
| public static class ApiException extends RuntimeException { | |||
| public final int statusCode; | |||
| public final String body; | |||
| public final Headers headers; | |||
| public ApiException(int statusCode, String body, Headers headers) { | |||
| super(String.format("微信支付API访问失败,StatusCode: %s, Body: %s", statusCode, body)); | |||
| this.statusCode = statusCode; | |||
| this.body = body; | |||
| this.headers = headers; | |||
| } | |||
| } | |||
| } | |||
| @ -0,0 +1,28 @@ | |||
| -----BEGIN PRIVATE KEY----- | |||
| MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDbf3wf7CEzvn1s | |||
| PqxYEKGxBeOo9DlGBUgbpnRNwWNB+HS2D8+6+tMcQE6H9eHylvMIKAz0wo+stHr9 | |||
| rNel14cNkZwnJT11BignzNPUYiMtKU690tFTD9SWeoM9ioWe6M/E6sGJ0X/JelUL | |||
| gj5i3Ge/RCVeG+0HOVJzKb2GB8D8co8+MT+S4aE2k0LpMMr/bau3BHExN0XQgC2g | |||
| mK6cJ+h0RIApiKdkLD6EQy8bL0ltbjn6TegKbCKiV6ZD8hkOU9wIkpkggad2SqFv | |||
| UGP5v8BFJr2dqsqKBdVHBVkOZUtH2sdN/0kVPWq96Pg4cdAWkkHVZNfJh1uXtaPt | |||
| TT57LepRAgMBAAECggEBAK+5QTMBRJd7Ukf9aNZcAkaJc3hIhS2kftT8DrJNN1yS | |||
| P0WeJO0Jb0d3yCca11fyNwD5p12wAXv/RVOfM0mm4Y0gXIYOT0RHuJAccB3gr06x | |||
| ekOH6mL4EnaiAD2dj1noAqYgVu8x1H8FO96p164ny7sZIF1WOA2He5WM/hi2Tm8K | |||
| /7vflB6EXvASC1zl/dKYqbu+6UbCZnlZo3mhN7cSdYWwvmfoS+FJJm2LhGTOEIV7 | |||
| Aotzv32FWq6nJvHGpF5BG3xvBxGPaiDlPNoMA5idPcnqAG253y2mR3MIVTHBesoi | |||
| MGPEEjuqXpzTCfs76XpuQtsqlj6/ewP1XI0weLK0TAECgYEA+kZwUHC63uOrj3eP | |||
| PwuCe0I2GNqowYjniEgRzaT4CYo+cEHn2LPLz3dVPlu5IgvdNPGwccQ8/rLfBLcq | |||
| HpMPb8s6+r/HB6bhHY8qQQFOUzq1cIVaNTHf90XSYTetIE0ytzmAUNwMsbPiGZoX | |||
| u74OdKOv2FntVc6BJ1zbC0DMthECgYEA4ITSOyqZkhcZoNbsNd/9TKqIhJW3I+ki | |||
| H+vUCaR81BEcMGhAcC4G9Zj246fAQObf/YWwRFapgttB28UDAcqIixuogml15EUB | |||
| X53Obca0aAsuLO/nPtyglb3J0Gs2IM2JwVQ9wOOXL5RsfagYpSkTOdVoqOkSdV4X | |||
| /n3F54GIsEECgYAtleDlNfNDn9Ji2lMUF6OXkdLKqiEsxyPs9buQamjnS+/dgJOb | |||
| K/yGeGTla82HvwN2nkMWJbk6ZxgqArbAROb95NWEUKQO571/JdF7b6J1lG7x5Mgu | |||
| gjwaDPSp0ntNM+J17xpJIBuLzojzQtbp0k9NvXbNAGwzQd7SbZ5UKWRgEQKBgHW+ | |||
| 8oo5AyUMnFIvpN10ROEqJkJySgO5Rj47bY5JB3YoKwJwCitK2DeBKymlVjwzWJEa | |||
| xaBxWqDX4CgjoDoWP5nEvZD3Qe6fCeNdXV9Q8FgIVQUYI8xh5I3jZK27LD3zzSTo | |||
| yyIXubgoPOWBfLtRWVXhR+wdn6KR4D+FMn8A/fCBAoGBAPiRyYHRiW43lYyNVfZt | |||
| w51CrVkSX/MqUnueRFtayugE0NDm7HTSEpUiOsblOJbTD6lQAnQbrawwScy0jlC2 | |||
| O/W/oIpP7cCV4OBkhjcS4dTSsK4XuC8fG7tknpvGFMxN/q3eH19K1lnVVg6UY8No | |||
| Djx1ieIkZjB8yIoppFMFhGFx | |||
| -----END PRIVATE KEY----- | |||
| @ -0,0 +1,9 @@ | |||
| -----BEGIN PUBLIC KEY----- | |||
| MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAysc3xWIYej0NzfZzMgvc | |||
| ZikTIb6xPcc+UW3fckNd4E2A9bJkgzACKkTtxCYWxDq2GYqCgUSjhk4hI7IfmkNr | |||
| bRomGPreDEsj5+rtnZmW3Qlv7G+YaMCeqKe/LPS7i8nh3NwDP/DGg2fOKHkrAEZS | |||
| Yvrxnx60EKiQPuBksx3pYcpD/41lAarpIHrIHoaxuu1AOCXVQ/3hgKDsczAdzDS/ | |||
| aZod2V60jSfcgxLW5wsyTOzYNMX+mksQkyy7oFfwp60/nhEy0wErduPHY9zR/by5 | |||
| /uyrhrZXZXK8TZNUdUHkLEHVTSFuv2FulDvk8+OCNaK7SZHh2sAqrvH0oQ1GQ8iO | |||
| 4wIDAQAB | |||
| -----END PUBLIC KEY----- | |||