0
点赞
收藏
分享

微信扫一扫

聚合支付项目-21

早安地球 2023-12-31 阅读 25

3.4 资质申请

3.4.1 商户服务-资质申请(接口②)

3.4.1.1 接口定义

1、接口描述

1)接收资质申请信息,更新商户信息及审核状态(待审核)

2)返回结果

2、接口定义如下:

在 MerchantService中定义applyMerchant接口

/**
 * 资质申请接口
 * @param merchantId 商户id
 * @param merchantDTO 资质申请的信息
 * @throws BusinessException
 */
void applyMerchant(Long merchantId,MerchantDTO merchantDTO) throws BusinessException;

3.4.1.2 接口实现

实现MerchantServiceImpl 中的applyMerchant方法

/**
  * 资质申请接口
  * @param merchantId  商户id
  * @param merchantDTO 资质申请的信息
  * @throws BusinessException
  */
 @Override
 @Transactional
 public void applyMerchant(Long merchantId, MerchantDTO merchantDTO) throws BusinessException {
     if(merchantId == null || merchantDTO == null){
         throw new BusinessException(CommonErrorCode.E_300009);
     }
     //校验merchantId合法性,查询商户表,如果查询不到记录,认为非法
     Merchant merchant = merchantMapper.selectById(merchantId);
     if(merchant == null){
         throw new BusinessException(CommonErrorCode.E_200002);
     }
     //将dto转成entity
     Merchant entity = MerchantConvert.INSTANCE.dto2entity(merchantDTO);
     //将必要的参数设置到entity
     entity.setId(merchant.getId());
     entity.setMobile(merchant.getMobile());//因为资质申请的时候手机号不让改,还使用数据库中原来的手机号
     entity.setAuditStatus("1");//审核状态1-已申请待审核
     entity.setTenantId(merchant.getTenantId());
     //调用mapper更新商户表
     merchantMapper.updateById(entity);
 }

3.2.4 商户平台应用-资质申请(接口③)

3.2.4.1 接口定义

1、接口描述

1)商户登录惠民支付平台

2)商户上传证件,填写资质信息

3)请求商户平台应用进行资质申请

4)商户平台应用请求商户服务完成资质申请

5)返回结果

2、接口定义如下:

根据原型编写商户资质申请VO:MerchantDetailVO

package com.huiminpay.merchant.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 资质申请信息
 * @author Administrator
 * @version 1.0
 **/
@ApiModel(value = "MerchantDetailVO", description = "商户资质申请信息")
@Data
public class MerchantDetailVO implements Serializable {

    @ApiModelProperty("企业名称")
    private String merchantName;

    @ApiModelProperty("企业编号")
    private String merchantNo;

    @ApiModelProperty("企业地址")
    private String merchantAddress;

    @ApiModelProperty("行业类型")
    private String merchantType;

    @ApiModelProperty("营业执照")
    private String businessLicensesImg;

    @ApiModelProperty("法人身份证正面")
    private String idCardFrontImg;

    @ApiModelProperty("法人身份证反面")
    private String idCardAfterImg;

    @ApiModelProperty("联系人")
    private String username;

    @ApiModelProperty("联系人地址")
    private String contactsAddress;

}

在MerchantController中定义saveMerchant

@ApiOperation("资质申请")
 @PostMapping("/my/merchants/save")
 @ApiImplicitParams({
     @ApiImplicitParam(name = "merchantInfo", value = "商户认证资料", required = true, dataType = "MerchantDetailVO", paramType = "body")
 })
 public void saveMerchant(@RequestBody  MerchantDetailVO merchantInfo){
 
 }

3.2.4.2 获取商户身份

1、商户登录临时方案

因前期未实现登录功能,故目前手动指定的商户ID生成Token(用户登录后的身份令牌),将Token配置在前端, 前端拥有了token则说明该商户Id对应的商户登录成功。

商户登录及身份解析流程如下:

1)前端携带token访问商户平台应用。

2)商户平台应用解析token取出商户id

2、生成token

拷贝“资料”-->"代码"下的 TokenTemp.java 到商户平台应用的test下。

代码如下:

package com.huiminpay.merchant.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huiminpay.common.util.EncryptUtil;
import com.huiminpay.merchant.api.MerchantService;
import com.huiminpay.merchant.api.dto.MerchantDTO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class TokenTemp {

    @Autowired
    MerchantService merchantService;

    //生成token,指定商户id
    @Test
    public void createTestToken() {
        Long merchantId = 1211232081483444226L;//填写用于测试的商户id
        MerchantDTO merchantDTO = merchantService.queryMerchantById(merchantId);
        JSONObject token = new JSONObject();
        token.put("mobile", merchantDTO.getMobile());
        token.put("user_name", merchantDTO.getUsername());
        token.put("merchantId", merchantId);

        String jwt_token = "Bearer " + EncryptUtil.encodeBase64(JSON.toJSONString(token).getBytes());
        System.out.println(jwt_token);
    }
}

向merchantId中设置商户id,运行此测试方法。(运行测试之前停止商户平台应用服务)

3、暂时使用工具类从请求中获取Token并解析

从“资料”--》“代码”文件夹拷贝“util(模拟token)”目录下的SecurityUtil及相关类到商户平台应用工程的util包下

3.2.4.3 资质申请实现

1)编写对象转换类

package com.huiminpay.merchant.convert;

import com.huiminpay.merchant.api.dto.MerchantDTO;
import com.huiminpay.merchant.vo.MerchantDetailVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * 将商户资质申请vo和dto进行转换
 * Created by Administrator.
 */
@Mapper
public interface MerchantDetailConvert {
    MerchantDetailConvert INSTANCE = Mappers.getMapper(MerchantDetailConvert.class);
    //将dto转成vo
    MerchantDetailVO dto2vo(MerchantDTO merchantDTO);
    //将vo转成dto
    MerchantDTO vo2dto(MerchantDetailVO merchantDetailVO);
}

2)编写MerchantController中的saveMerchant方法

前端携带Token请求此方法,在此方法中需要解析token获取当前商户的Id。

@ApiOperation("资质申请")
@PostMapping("/my/merchants/save")
@ApiImplicitParams({
    @ApiImplicitParam(name = "merchantInfo", value = "商户认证资料", required = true, dataType = "MerchantDetailVO", paramType = "body")
})
public void saveMerchant(@RequestBody MerchantDetailVO merchantInfo){
    //解析token,取出当前登录商户的id
    Long merchantId = SecurityUtil.getMerchantId();

    //Long merchantId,MerchantDTO merchantDTO
    MerchantDTO merchantDTO = MerchantDetailConvert.INSTANCE.vo2dto(merchantInfo);
    merchantService.applyMerchant(merchantId,merchantDTO);
}

3.2.4.4 接口测试

1、生成token

运行 createTestToken 测试方法生成临时token。

在Header中添加 :key:authorization value:token

例子如下 :

注意:token内容前边固定添加 “Bearer ” (后边一个空格 )

2、上传证件,获取证件标识

参考证件上传测试。

3、资质申请

请求数据:

{ 
 "merchantName": "学生餐厅", 
 "merchantNo": "1376438579462737921", 
 "merchantType": "餐饮", 
 "merchantAddress": "郑州梧桐创业大厦", 
 "contactsAddress": "郑州梧桐街", 
 "businessLicensesImg": "https://xwh0330.oss-cn-beijing.aliyuncs.com/1617086663126.jpg", 
 "idCardAfterImg": "https://xwh0330.oss-cn-beijing.aliyuncs.com/1617086663126.jpg", 
 "idCardFrontImg": "https://xwh0330.oss-cn-beijing.aliyuncs.com/1617086663126.jpg", 
 "username":"张先生" 
}

举报

相关推荐

0 条评论