浏览代码

H5接口与区县问题添加

小么熊🐻 2 年之前
父节点
当前提交
2451fa86ca

+ 15 - 0
nbjk-admin/src/main/java/com/miaxis/app/controller/exam/ExamInfoController.java

@@ -17,6 +17,7 @@ import com.miaxis.exam.domain.ExamInfo;
 import com.miaxis.exam.dto.ExamInfoDto;
 import com.miaxis.exam.service.IExamInfoService;
 import com.miaxis.exam.vo.ExamInfoCityVo;
+import com.miaxis.exam.vo.ExamInfoCountyVo;
 import com.miaxis.exam.vo.ExamInfoProviceVo;
 import com.miaxis.exam.vo.ExamInfoVipVo;
 import io.swagger.annotations.*;
@@ -125,6 +126,20 @@ public class ExamInfoController extends BaseController {
         return Response.success(examInfoService.getCity(proviceId));
     }
 
+
+    /**
+     * 根据城市ID获取考场区县
+     */
+    @GetMapping(value = "/county/{cityId}")
+    @ApiOperation("根据城市ID获取考场区县")
+    public Response<List<ExamInfoCountyVo>> getCounty(
+            @ApiParam(name = "cityId", value = "考场信息参数", required = true)
+            @PathVariable("cityId") String cityId
+    ) {
+        return Response.success(examInfoService.getCounty(cityId));
+    }
+
+
     @GetMapping(value = "/ip")
     @ApiOperation("根据访问IP获取地址")
     public Response<Map<String, Object>> exampleMethod() throws IOException, GeoIp2Exception {

+ 99 - 0
nbjk-admin/src/main/java/com/miaxis/app/controller/wx/WxController.java

@@ -11,6 +11,8 @@ import com.miaxis.common.core.domain.entity.UserInfo;
 import com.miaxis.common.enums.OrderStatusEnum;
 import com.miaxis.common.exception.CustomException;
 import com.miaxis.common.utils.SecurityUtils;
+import com.miaxis.common.utils.ServletUtils;
+import com.miaxis.common.utils.ip.IpUtils;
 import com.miaxis.common.utils.uuid.CommonUtils;
 import com.miaxis.exam.domain.ExamInfo;
 import com.miaxis.exam.service.IExamInfoService;
@@ -84,6 +86,15 @@ public class WxController extends BaseController {
     @Value("${app.appId}")
     private String appId;
 
+    @Value("${app.bundleId}")
+    private String bundleId;
+
+    @Value("${app.packageName}")
+    private String packageName;
+
+    @Value("${gzh.appId}")
+    private String gzhAppId;
+
     @Value("${wxpay.notifyUrl}")
     private  String notifyUrl ;
 
@@ -326,6 +337,94 @@ public class WxController extends BaseController {
 
 
 
+    /**
+     * 微信小程序支付获取预订单id
+     */
+    @PostMapping(value = "/h5PrepareOrder")
+    @ApiOperation("微信H5支付下单")
+    public Response<JSONObject> h5PrepareOrder(@RequestBody WxOrderDTO wxOrderDTO) throws Exception{
+        UserInfo userInfo = SecurityUtils.getLoginUser().getStudent();
+        if(wxOrderDTO.getGoodsType()==1) {
+            int count = vipUserExamService.getUserExamByUnionIdAndGoodsId(userInfo.getUnionId(), wxOrderDTO.getGoodsId());
+            if (count > 0) {
+                throw new CustomException("您已购买过该考场,退回上个页面,重新进入。");
+            }
+            ExamInfo examInfo = examInfoService.getById(wxOrderDTO.getGoodsId());
+            //创建本地微信订单
+            WxOrder order = new WxOrder();
+            String orderCode = getOrderCode(userInfo.getId());
+            order.setGoodsId(wxOrderDTO.getGoodsId());
+            order.setGoodsName(examInfo.getName());
+            order.setGoodsType(1);
+            order.setOutTradeNo(orderCode);
+            order.setUserId(userInfo.getId());
+            order.setXcxOpenid(userInfo.getXcxOpenid());
+            order.setAppOpenid(userInfo.getAppOpenid());
+            order.setGzhOpenid(userInfo.getGzhOpenid());
+            order.setUnionId(userInfo.getUnionId());
+            order.setPhoneType(wxOrderDTO.getPhoneType()); //手机类型 1:苹果 2:安卓
+            order.setForeType(wxOrderDTO.getForeType()); //前端类型 1:app 2:小程序 3:公众号
+            order.setTotal(examInfo.getPrice());
+            order.setOrderStatus(OrderStatusEnum.PROCESSING.getCode());
+            wxOrderService.save(order);
+            return Response.success(placeH5WxOrder(order, examInfo.getName()));
+        } else if (wxOrderDTO.getGoodsType()==2) {
+            throw new CustomException("请正确传入GoodsType,GoodsType=2未开发");
+        } else {
+            throw new CustomException("请正确传入GoodsType。");
+        }
+    }
+
+
+
+
+    /**
+     * 微信H5下单
+     * @param order
+     * @param goodsName
+     * @return
+     * @throws Exception
+     */
+    private JSONObject placeH5WxOrder(WxOrder order, String goodsName) throws Exception {
+        HttpPost httpPost = initHttpPost(wxpayConfig.getV3JsUrl());
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        ObjectMapper objectMapper = new ObjectMapper();
+        ObjectNode rootNode = objectMapper.createObjectNode();
+        ObjectNode sceneInfoNode = objectMapper.createObjectNode();
+        ObjectNode h5InfoNode = objectMapper.createObjectNode();
+        rootNode.put("mchid",wxpayConfig.getMerchantId())
+                .put("appid", gzhAppId)
+                .put("description", goodsName)
+                .put("notify_url", notifyUrl)
+                .put("out_trade_no", order.getOutTradeNo());
+        rootNode.putObject("amount").put("total", order.getTotal()).put("currency","CNY");
+
+        //前端类型 1:app 2:小程序 3:公众号
+        if(order.getPhoneType()==1 && order.getForeType()==1){ //1苹果  又是APP中支付
+            h5InfoNode.put("type", "iOS");
+            h5InfoNode.put("bundle_id",bundleId);
+        } else if (order.getPhoneType()==2 && order.getForeType()==1){ //2安卓 又是APP中支付
+            h5InfoNode.put("type", "Android");
+            h5InfoNode.put("package_name",packageName);
+        } else {
+            h5InfoNode.put("type", "Wap");
+        }
+        String ipAddr = IpUtils.getIpAddr(ServletUtils.getRequest()); //获取请求IP
+        sceneInfoNode.put("payer_client_ip", ipAddr)
+                .set("h5_info", h5InfoNode);
+        rootNode.set("scene_info",sceneInfoNode);
+
+        objectMapper.writeValue(bos, rootNode);
+        httpPost.setEntity(new StringEntity(rootNode.toString(), "utf-8"));
+        HttpResponse response = httpClient.execute(httpPost);
+        String bodyAsString = EntityUtils.toString(response.getEntity());
+        if (JSONObject.parseObject(bodyAsString).get("prepay_id") == null){
+            throw new CustomException(JSONObject.parseObject(bodyAsString).get("message").toString());
+        }
+        return getWxParamJson(bodyAsString);
+
+    }
+
 
 
 

+ 3 - 0
nbjk-admin/src/main/resources/application-dev.yml

@@ -98,6 +98,8 @@ spring:
 app:
     appId: wxfb80ed2dac7a6bb9
     appSecret: ac7eb47efc59f3cdbec46d3bf3a68627
+    bundleId: com.money.NBJiaKao
+    packageName: com.money.NiuBiJiaKao
 
 # 微信公众号
 gzh:
@@ -114,6 +116,7 @@ xcx:
 wxpay:
     v3url: https://api.mch.weixin.qq.com/v3/pay/transactions/app
     v3JsUrl: https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi
+    v3H5Url: https://api.mch.weixin.qq.com/v3/pay/transactions/h5
     v3urlRefund: https://api.mch.weixin.qq.com/v3/refund/domestic/refunds
     merchantId: 1639487489
     serialNumber: 1304D67DC59D94217412C49E20D5B0E00A5A122D

+ 3 - 0
nbjk-admin/src/main/resources/application-local.yml

@@ -98,6 +98,8 @@ spring:
 app:
     appId: wxfb80ed2dac7a6bb9
     appSecret: ac7eb47efc59f3cdbec46d3bf3a68627
+    bundleId: com.money.NBJiaKao
+    packageName: com.money.NiuBiJiaKao
 
 # 微信公众号
 gzh:
@@ -113,6 +115,7 @@ xcx:
 wxpay:
     v3url: https://api.mch.weixin.qq.com/v3/pay/transactions/app
     v3JsUrl: https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi
+    v3H5Url: https://api.mch.weixin.qq.com/v3/pay/transactions/h5
     v3urlRefund: https://api.mch.weixin.qq.com/v3/refund/domestic/refunds
     merchantId: 1639487489
     serialNumber: 1304D67DC59D94217412C49E20D5B0E00A5A122D

+ 3 - 0
nbjk-admin/src/main/resources/application-prod.yml

@@ -99,6 +99,8 @@ spring:
 app:
     appId: wxfb80ed2dac7a6bb9
     appSecret: ac7eb47efc59f3cdbec46d3bf3a68627
+    bundleId: com.money.NBJiaKao
+    packageName: com.money.NiuBiJiaKao
 
 # 微信公众号
 gzh:
@@ -114,6 +116,7 @@ xcx:
 wxpay:
     v3url: https://api.mch.weixin.qq.com/v3/pay/transactions/app
     v3JsUrl: https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi
+    v3H5Url: https://api.mch.weixin.qq.com/v3/pay/transactions/h5
     v3urlRefund: https://api.mch.weixin.qq.com/v3/refund/domestic/refunds
     merchantId: 1639487489
     serialNumber: 1304D67DC59D94217412C49E20D5B0E00A5A122D

+ 2 - 1
nbjk-common/src/main/java/com/miaxis/common/config/WxpayConfig.java

@@ -12,7 +12,8 @@ public class WxpayConfig {
     private String v3url;
     //小程序 公众号微信体系内支付下单地址
     private String v3JsUrl;
-
+    //H5 微信支付下单
+    private String v3H5Url;
     //退款
     private String v3urlRefund;
     //退款回调

+ 6 - 0
nbjk-service/src/main/java/com/miaxis/exam/mapper/ExamInfoMapper.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.miaxis.exam.domain.ExamInfo;
 import com.miaxis.exam.dto.ExamInfoDto;
 import com.miaxis.exam.vo.ExamInfoCityVo;
+import com.miaxis.exam.vo.ExamInfoCountyVo;
 import com.miaxis.exam.vo.ExamInfoProviceVo;
 import com.miaxis.exam.vo.ExamInfoVipVo;
 
@@ -39,10 +40,15 @@ public interface ExamInfoMapper extends BaseMapper<ExamInfo> {
      */
     List<ExamInfoCityVo> getCity(String proviceId);
 
+
+    List<ExamInfoCountyVo> getCounty(String cityId);
+
     /**
      * 查询我的考场
      * @param examInfoDto
      * @return
      */
     List<ExamInfoVipVo> selectMyExamInfoList(ExamInfoDto examInfoDto);
+
+
 }

+ 4 - 0
nbjk-service/src/main/java/com/miaxis/exam/service/IExamInfoService.java

@@ -5,6 +5,7 @@ import com.miaxis.exam.domain.ExamInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.miaxis.exam.dto.ExamInfoDto;
 import com.miaxis.exam.vo.ExamInfoCityVo;
+import com.miaxis.exam.vo.ExamInfoCountyVo;
 import com.miaxis.exam.vo.ExamInfoProviceVo;
 import com.miaxis.exam.vo.ExamInfoVipVo;
 
@@ -29,5 +30,8 @@ public interface IExamInfoService extends IService<ExamInfo>{
 
     List<ExamInfoCityVo> getCity(String proviceId);
 
+    List<ExamInfoCountyVo> getCounty(String cityId);
+
     List<ExamInfoVipVo> selectMyExamInfoList(ExamInfoDto examInfoDto);
+
 }

+ 6 - 0
nbjk-service/src/main/java/com/miaxis/exam/service/impl/ExamInfoServiceImpl.java

@@ -4,6 +4,7 @@ import java.util.List;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.miaxis.exam.dto.ExamInfoDto;
 import com.miaxis.exam.vo.ExamInfoCityVo;
+import com.miaxis.exam.vo.ExamInfoCountyVo;
 import com.miaxis.exam.vo.ExamInfoProviceVo;
 import com.miaxis.exam.vo.ExamInfoVipVo;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -49,6 +50,11 @@ public class ExamInfoServiceImpl extends ServiceImpl<ExamInfoMapper, ExamInfo> i
         return examInfoMapper.getCity(proviceId);
     }
 
+    @Override
+    public List<ExamInfoCountyVo> getCounty(String cityId) {
+        return examInfoMapper.getCounty(cityId);
+    }
+
     @Override
     public List<ExamInfoVipVo> selectMyExamInfoList(ExamInfoDto examInfoDto) {
         return examInfoMapper.selectMyExamInfoList(examInfoDto);

+ 26 - 0
nbjk-service/src/main/java/com/miaxis/exam/vo/ExamInfoCountyVo.java

@@ -0,0 +1,26 @@
+package com.miaxis.exam.vo;
+
+import com.miaxis.common.core.domain.BaseBusinessEntity;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 考场信息对象 exam_info
+ *
+ * @author miaxis
+ * @date 2023-03-20
+ */
+@Data
+@ApiModel(value = "ExamInfoCityVo", description = "考场信息城市返回值")
+public class ExamInfoCountyVo extends BaseBusinessEntity{
+    private static final long serialVersionUID = 1L;
+
+    /** 城市ID */
+    @ApiModelProperty(value = "城市ID")
+    private String countyId;
+
+    /** 城市名称 */
+    @ApiModelProperty(value = "城市名称")
+    private String county;
+}

+ 7 - 0
nbjk-service/src/main/resources/mapper/exam/ExamInfoMapper.xml

@@ -97,4 +97,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         GROUP BY city_id,city
     </select>
 
+    <select id="getCounty" resultType="com.miaxis.exam.vo.ExamInfoCountyVo">
+        select county_id,county from exam_info where county_id_id = #{countyId}
+        GROUP BY county_id,county
+    </select>
+
+
+
 </mapper>