release:前端请求简税对接大象登陆

master
路明慧 1 year ago
parent b9d4b907e8
commit 7df7d9dcff
  1. 201
      jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceFrontController.java
  2. 37
      jianshui-common/src/main/java/com/jianshui/common/constant/PersonList.java
  3. 20
      jianshui-invoice/src/main/java/com/jianshui/invoice/service/ElephantInvoiceService.java
  4. 149
      jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/ElephantInvoiceServiceImpl.java

@ -0,0 +1,201 @@
package com.jianshui.api.controller.http.invoice.v1;
import com.alibaba.fastjson.JSONObject;
import com.jianshui.common.core.domain.AjaxResult;
import com.jianshui.common.core.domain.entity.Companyservice;
import com.jianshui.common.enums.ErrorCode;
import com.jianshui.common.utils.StringUtils;
import com.jianshui.invoice.service.ElephantInvoiceService;
import com.jianshui.system.service.ICompanyserviceService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/api/invoice/front/v1")
public class InvoiceFrontController {
@Autowired
private ICompanyserviceService iCompanyserviceService;
@Autowired
private ElephantInvoiceService elephantInvoiceService;
/**
* 数电登录接口(前端使用)
*/
@ApiImplicitParams({
@ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.String", example = "1130", required = true),
@ApiImplicitParam(name = "secret", value = "身份认证Key", dataType = "java.lang.String", example = "LTEO+oOgWMsuQAOUglqXuQ==", required = true),
@ApiImplicitParam(name = "params", value = "请求体", dataType = "java.lang.String", required = true)
})
@PostMapping("/rpaLogin/{identity}/{secret}")
public Object rpaLogin(@RequestBody Map<String,Object> params,@PathVariable("identity") String identity, @PathVariable("secret") String secret) {
JSONObject paramJson = new JSONObject(params);
log.debug("rpaLogin param{} identity:{} secret:{}", paramJson.toJSONString(), identity, secret);
//参数校验
if (StringUtils.isBlank(identity)){
return AjaxResult.error("公司ID不能为空");
}
if (StringUtils.isBlank(secret)){
return AjaxResult.error("公司Key不能为空");
}
if (StringUtils.isBlank(paramJson.getString("yhm"))){
return AjaxResult.error("电子税局登录名不能为空");
}
if (StringUtils.isBlank(paramJson.getString("mm"))){
return AjaxResult.error("电子税局密码不能为空");
}
//方法名处理
if (StringUtils.isBlank(paramJson.getString("ffm"))){
return AjaxResult.error("方法名不能为空");
}
if ("0".equals(paramJson.getString("ffm"))){
paramJson.put("ffm","login");
}
if ("1".equals(paramJson.getString("ffm"))){
paramJson.put("ffm","send_sms");
}
if ("2".equals(paramJson.getString("ffm"))){
if (StringUtils.isBlank(paramJson.getString("zrrlx"))){
return AjaxResult.error("责任人类型不能为空");
}
paramJson.put("ffm","select_zrrlx");
}
if ("3".equals(paramJson.getString("ffm"))){
if (StringUtils.isBlank(paramJson.getString("dxyzm"))){
return AjaxResult.error("短信验证码不能为空");
}
paramJson.put("ffm","sms_login");
}
Companyservice companyservice = iCompanyserviceService.selectCompanyserviceByIdentity(identity);
if (companyservice == null || !secret.equals(companyservice.getSecret())) {
return AjaxResult.error(ErrorCode.COMPANY_NOT_FOUND);
}
return elephantInvoiceService.rpaLogin(paramJson,companyservice);
}
/**
* 数电账号查询接口(前端使用)
*/
@ApiImplicitParams({
@ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.String", example = "1130", required = true),
@ApiImplicitParam(name = "secret", value = "身份认证Key", dataType = "java.lang.String", example = "LTEO+oOgWMsuQAOUglqXuQ==", required = true)
})
@PostMapping("/queryRpaTaxAccount/{identity}/{secret}")
public Object queryRpaTaxAccount(@PathVariable("identity") String identity, @PathVariable("secret") String secret ){
log.debug("queryRpaTaxAccount param identity:{} secret:{}",identity,secret);
//参数校验
if (StringUtils.isBlank(identity)){
return AjaxResult.error("公司ID不能为空");
}
if (StringUtils.isBlank(secret)){
return AjaxResult.error("公司Key不能为空");
}
Companyservice companyservice = iCompanyserviceService.selectCompanyserviceByIdentity(identity);
if (companyservice == null || !secret.equals(companyservice.getSecret())) {
return AjaxResult.error(ErrorCode.COMPANY_NOT_FOUND);
}
return elephantInvoiceService.queryRpaTaxAccount(companyservice.getSellertax(),companyservice);
}
/**
* 数电获取二维码接口(前端使用)
*/
@ApiImplicitParams({
@ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.String", example = "1130", required = true),
@ApiImplicitParam(name = "secret", value = "身份认证Key", dataType = "java.lang.String", example = "LTEO+oOgWMsuQAOUglqXuQ==", required = true),
@ApiImplicitParam(name = "yhm", value = "电子税局登陆账号", dataType = "java.lang.String", required = true)
})
@PostMapping("/getRpaQrCode/{identity}/{secret}")
public Object getRpaQrCode(@RequestBody Map<String,Object> params,@PathVariable("identity") String identity, @PathVariable("secret") String secret ) {
JSONObject paramJson = new JSONObject(params);
log.debug("getRpaQrCode param params:{} identity:{} secret:{}", paramJson,identity,secret);
//参数校验
if (StringUtils.isBlank(identity)){
return AjaxResult.error("公司ID不能为空");
}
if (StringUtils.isBlank(secret)){
return AjaxResult.error("公司Key不能为空");
}
if (StringUtils.isBlank(paramJson.getString("yhm"))){
return AjaxResult.error("电子税局登录名不能为空");
}
Companyservice companyservice = iCompanyserviceService.selectCompanyserviceByIdentity(identity);
if (companyservice == null || !secret.equals(companyservice.getSecret())) {
return AjaxResult.error(ErrorCode.COMPANY_NOT_FOUND);
}
return elephantInvoiceService.getRpaQrCode(paramJson,companyservice);
}
/**
* 数电登录接口(前端使用)
*/
@ApiImplicitParams({
@ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.String", example = "1130", required = true),
@ApiImplicitParam(name = "secret", value = "身份认证Key", dataType = "java.lang.String", example = "LTEO+oOgWMsuQAOUglqXuQ==", required = true),
@ApiImplicitParam(name = "params", value = "请求体", dataType = "java.lang.String", required = true)
})
@PostMapping("/getRpaAuthStatus/{identity}/{secret}")
public Object getRpaAuthStatus(@RequestBody Map<String,Object> params, @PathVariable("identity") String identity, @PathVariable("secret") String secret ) {
JSONObject paramJson = new JSONObject(params);
log.debug("getRpaAuthStatus param{} identity:{} secret:{}", paramJson.toJSONString(), identity, secret);
//参数校验
if (StringUtils.isBlank(identity)){
return AjaxResult.error("公司ID不能为空");
}
if (StringUtils.isBlank(secret)){
return AjaxResult.error("公司Key不能为空");
}
if (StringUtils.isBlank(paramJson.getString("rzid"))){
return AjaxResult.error("认证ID不能为空");
}
Companyservice companyservice = iCompanyserviceService.selectCompanyserviceByIdentity(identity);
if (companyservice == null || !secret.equals(companyservice.getSecret())) {
return AjaxResult.error(ErrorCode.COMPANY_NOT_FOUND);
}
return elephantInvoiceService.getRpaAuthStatus(paramJson,companyservice);
}
}

@ -0,0 +1,37 @@
package com.jianshui.common.constant;
public enum PersonList {
PERSON_TYPE_01("01", "法定代表人"),
PERSON_TYPE_02("02", "财务负责人"),
PERSON_TYPE_03("03", "办税员"),
PERSON_TYPE_05("05", "管理员"),
PERSON_TYPE_08("08", "社保经办人"),
PERSON_TYPE_09("09", "开票员"),
PERSON_TYPE_10("10", "销售人员");
private String type;
private String name;
PersonList(String type, String name){
this.type = type;
this.name = name;
}
public String getType(){
return type;
}
public String getName(){
return name;
}
public static String getName(String type){
for(PersonList personList : PersonList.values()){
if(personList.getType().equals(type)){
return personList.getName();
}
}
return "未知类型";
}
}

@ -0,0 +1,20 @@
package com.jianshui.invoice.service;
import com.alibaba.fastjson.JSONObject;
import com.jianshui.common.core.domain.AjaxResult;
import com.jianshui.common.core.domain.entity.Companyservice;
public interface ElephantInvoiceService {
//查询电子税局账户
AjaxResult queryRpaTaxAccount(String sellertax, Companyservice companyservice);
//数电账户登陆
AjaxResult rpaLogin(JSONObject paramJson, Companyservice companyservice);
//获取二维码
AjaxResult getRpaQrCode(JSONObject paramJson, Companyservice companyservice);
//获取状态
AjaxResult getRpaAuthStatus(JSONObject paramJson, Companyservice companyservice);
}

@ -0,0 +1,149 @@
package com.jianshui.invoice.service.impl;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dxhy.order.protocol.invoke.DxhyInterfaceResponse;
import com.jianshui.common.constant.PersonList;
import com.jianshui.common.core.domain.AjaxResult;
import com.jianshui.common.core.domain.entity.Companyservice;
import com.jianshui.common.utils.JsonKeyCase;
import com.jianshui.invoice.constant.elephant.ElephantConstantsV6;
import com.jianshui.invoice.domain.dto.HXResponse;
import com.jianshui.invoice.service.ElephantInvoiceService;
import com.jianshui.invoice.utils.elephant.ElephantUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class ElephantInvoiceServiceImpl implements ElephantInvoiceService {
//调用大象获取电子税局账号
@Override
public AjaxResult queryRpaTaxAccount(String sellertax, Companyservice companyservice) {
Map<String,String> param = new HashMap<>();
param.put("NSRSBH",sellertax);
DxhyInterfaceResponse dxhyInterfaceResponse = null;
try {
log.info("front queryRpaTaxAccount param{}",JSONObject.toJSONString(param));
dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.QUERY_RPA_TAX_ACCOUNT_LOCALHOST, ElephantConstantsV6.QUERY_RPA_TAX_ACCOUNT_METHOD, JSONUtil.parse(param), companyservice);
log.info("front queryRpaTaxAccount response{}",JSONObject.toJSONString(dxhyInterfaceResponse));
} catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) {
log.error("获取电子税局账号失败{}",e);
return AjaxResult.error("009999", "系统异常!");
}
if (!"000000".equals(dxhyInterfaceResponse.getCode())){
return AjaxResult.error(dxhyInterfaceResponse.getMessage());
}
JSONObject responJson = JSONObject.parseObject(dxhyInterfaceResponse.getData());
responJson = JsonKeyCase.JsonKeyCase(responJson,1);
if (!"000000".equals(responJson.getString("ztdm"))){
return AjaxResult.error(responJson.getString("ztxx"));
}
return AjaxResult.success(responJson.getJSONArray("data"));
}
//调用大象进行登录
@Override
public AjaxResult rpaLogin(JSONObject paramJson, Companyservice companyservice) {
paramJson.put("NSRSBH",companyservice.getSellertax());
DxhyInterfaceResponse dxhyInterfaceResponse = null;
try {
paramJson = JsonKeyCase.JsonKeyCase(paramJson);
log.info("front rpaLogin param{}",paramJson);
dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.RPA_LOGIN_LOCALHOST, ElephantConstantsV6.RPA_LOGIN_METHOD, JSONUtil.parse(paramJson), companyservice);
log.info("front rpaLogin response{}",JSONObject.toJSONString(dxhyInterfaceResponse));
} catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) {
log.error("电子税局登陆失败{}",e);
return AjaxResult.error("009999", "系统异常!");
}
if (!"000000".equals(dxhyInterfaceResponse.getCode())){
return AjaxResult.error(dxhyInterfaceResponse.getMessage());
}
//获取返回数据
JSONObject responJson = JSONObject.parseObject(dxhyInterfaceResponse.getData());
//key转成小写
responJson = JsonKeyCase.JsonKeyCase(responJson,1);
if (!"000000".equals(responJson.getString("ztdm"))){
return AjaxResult.error(responJson.getString("ztxx"));
}
//判断后续方法是否为3
JSONObject dataJson = responJson.getJSONObject("data");
if ("2".equals(dataJson.getString("hxff"))){
JSONObject sj = dataJson.getJSONObject("sj");
List<String> personList = sj.getJSONArray("personList").toJavaList(String.class);
Map<String,String> personTypes = new HashMap<>();
personList.forEach(e->personTypes.put(e, PersonList.getName(e)));
dataJson.put("personList",personTypes);
}
return AjaxResult.success(dataJson);
}
//获取二维码
@Override
public AjaxResult getRpaQrCode(JSONObject paramJson, Companyservice companyservice) {
paramJson.put("NSRSBH",companyservice.getSellertax());
DxhyInterfaceResponse dxhyInterfaceResponse = null;
try {
paramJson = JsonKeyCase.JsonKeyCase(paramJson);
log.info("front getRpaQrCode param{}",JSONObject.toJSONString(paramJson));
dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.GET_RPA_QY_CODE_LOCALHOST, ElephantConstantsV6.GET_RPA_QY_CODE_METHOD, JSONUtil.parse(paramJson), companyservice);
log.info("front getRpaQrCode response{}",JSONObject.toJSONString(dxhyInterfaceResponse));
} catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) {
log.error("电子税局登陆失败{}",e);
return AjaxResult.error("009999", "系统异常!");
}
if (!"000000".equals(dxhyInterfaceResponse.getCode())){
return AjaxResult.error(dxhyInterfaceResponse.getMessage());
}
JSONObject responJson = JSONObject.parseObject(dxhyInterfaceResponse.getData());
responJson = JsonKeyCase.JsonKeyCase(responJson,1);
if (!"000000".equals(responJson.getString("ztdm"))){
return AjaxResult.error(responJson.getString("ztxx"));
}
return AjaxResult.success(responJson.getJSONObject("data"));
}
//数电实名认证状态
@Override
public AjaxResult getRpaAuthStatus(JSONObject paramJson, Companyservice companyservice) {
paramJson.put("NSRSBH",companyservice.getSellertax());
DxhyInterfaceResponse dxhyInterfaceResponse = null;
try {
paramJson = JsonKeyCase.JsonKeyCase(paramJson);
log.info("front getRpaAuthStatus param{}",paramJson);
dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.GET_RPA_AUTH_STATUS_LOCALHOST, ElephantConstantsV6.GET_RPA_AUTH_STATUS_METHOD, JSONUtil.parse(paramJson), companyservice);
log.info("front getRpaAuthStatus response{}",JSONObject.toJSONString(dxhyInterfaceResponse));
} catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) {
log.error("电子税局登陆失败{}",e);
return AjaxResult.error("009999", "系统异常!");
}
if (!"000000".equals(dxhyInterfaceResponse.getCode())){
return AjaxResult.error(dxhyInterfaceResponse.getMessage());
}
JSONObject responJson = JSONObject.parseObject(dxhyInterfaceResponse.getData());
responJson = JsonKeyCase.JsonKeyCase(responJson,1);
if (!"000000".equals(responJson.getString("ztdm"))){
return AjaxResult.error(responJson.getString("ztxx"));
}
return AjaxResult.success(responJson.getJSONObject("data"));
}
}
Loading…
Cancel
Save