| @@ -0,0 +1,39 @@ | |||
| package com.iformall.domain.vo; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| public class WxPayOrderVo extends WxPayOrder { | |||
| @io.swagger.annotations.ApiModelProperty(value="用户绑定的openId",name="openId") | |||
| private String openId; | |||
| @io.swagger.annotations.ApiModelProperty(value="用户支付appId",name="appId") | |||
| private String appId; | |||
| @io.swagger.annotations.ApiModelProperty(value="支付ID,参看wx_pay_account",name="payId") | |||
| private Long payId; | |||
| public String getOpenId() { | |||
| return openId; | |||
| } | |||
| public void setOpenId(String openId) { | |||
| this.openId = openId; | |||
| } | |||
| public String getAppId() { | |||
| return appId; | |||
| } | |||
| public void setAppId(String appId) { | |||
| this.appId = appId; | |||
| } | |||
| public Long getPayId() { | |||
| return payId; | |||
| } | |||
| public void setPayId(Long payId) { | |||
| this.payId = payId; | |||
| } | |||
| } | |||
| @@ -3,8 +3,11 @@ package com.iformall.mapper; | |||
| import java.util.*; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.domain.vo.WxPayOrderVo; | |||
| public interface WxPayOrderMapper extends CommonMapper<WxPayOrder, Long> { | |||
| List<WxPayOrder> findList(WxPayOrder wxPayOrder); | |||
| List<WxPayOrderVo> findListOfPaidOrderByDate(Map dateMap); | |||
| } | |||
| @@ -83,7 +83,7 @@ | |||
| </if> | |||
| <if test=" null != prepayId "> | |||
| and `prepay_d` like concat('%', #{prepayId},'%') | |||
| and `prepay_id` like concat('%', #{prepayId},'%') | |||
| </if> | |||
| <if test=" null != transactionId "> | |||
| @@ -126,4 +126,53 @@ | |||
| <include refid="dynamicWhereConditions"/> | |||
| </select> | |||
| <resultMap id="VBaseResultMap" type="com.iformall.domain.vo.WxPayOrderVo"> | |||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||
| <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/> | |||
| <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/> | |||
| <result column="order_id" jdbcType="BIGINT" property="orderId"/> | |||
| <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/> | |||
| <result column="b_user_id" jdbcType="BIGINT" property="bUserId"/> | |||
| <result column="auth_code" jdbcType="VARCHAR" property="authCode"/> | |||
| <result column="ip" jdbcType="VARCHAR" property="ip"/> | |||
| <result column="pay_amount" jdbcType="INTEGER" property="payAmount"/> | |||
| <result column="pay_time_start" jdbcType="TIMESTAMP" property="payTimeStart"/> | |||
| <result column="pay_time_end" jdbcType="TIMESTAMP" property="payTimeEnd"/> | |||
| <result column="prepay_id" jdbcType="VARCHAR" property="prepayId"/> | |||
| <result column="transaction_id" jdbcType="VARCHAR" property="transactionId"/> | |||
| <result column="pay_vendor" jdbcType="INTEGER" property="payVendor"/> | |||
| <result column="pay_order_no" jdbcType="VARCHAR" property="payOrderNo"/> | |||
| <result column="pay_order_status" jdbcType="INTEGER" property="payOrderStatus"/> | |||
| <result column="share" jdbcType="INTEGER" property="share"/> | |||
| <result column="share_amount" jdbcType="INTEGER" property="shareAmount"/> | |||
| <result column="fail_reason" jdbcType="VARCHAR" property="failReason"/> | |||
| <result column="open_id" jdbcType="VARCHAR" property="openId"/> | |||
| <result column="app_id" jdbcType="VARCHAR" property="appId"/> | |||
| <result column="pay_id" jdbcType="BIGINT" property="payId"/> | |||
| </resultMap> | |||
| <sql id="allVColumns"> | |||
| p.`id`,p.`tenant_id`,p.`create_time`,p.`update_time`,p.`order_id`,p.`c_user_id`,p.`b_user_id`, | |||
| p.`auth_code`,p.`ip`,p.`pay_amount`,p.`pay_time_start`,p.`pay_time_end`, | |||
| p.`prepay_id`,p.`transaction_id`,p.`pay_vendor`,p.`pay_order_no`, | |||
| p.`pay_order_status`,p.`share`,p.`share_amount`,p.`fail_reason`, | |||
| u.`open_id`, | |||
| a.`app_id`, a.`pay_id` | |||
| </sql> | |||
| <select id="findListOfPaidOrderByDate" parameterType="map" resultMap="VBaseResultMap"> | |||
| select | |||
| <include refid="allVColumns"/> | |||
| from wx_pay_order p | |||
| left join wx_c_user u on p.`c_user_id` = u.`id` | |||
| left join wx_appinfo a on a.`tenant_id` = p.`tenant_id` and a.`type` = 2 | |||
| where p.`pay_order_status` = '1' and p.`pay_vendor` = 0 and u.`union_id` is null | |||
| <if test="startDate != null"> | |||
| AND unix_timestamp(p.`pay_time_end`) > unix_timestamp(#{startDate,jdbcType=TIMESTAMP}) | |||
| </if> | |||
| </select> | |||
| </mapper> | |||
| @@ -13,8 +13,8 @@ | |||
| <artifactId>mallinkWechatOpen</artifactId> | |||
| <properties> | |||
| <weixin-java-mp.version>3.3.0</weixin-java-mp.version> | |||
| <weixin-java-open.version>3.3.0</weixin-java-open.version> | |||
| <weixin-java-mp.version>3.3.0.A</weixin-java-mp.version> | |||
| <weixin-java-open.version>3.3.0.A</weixin-java-open.version> | |||
| </properties> | |||
| <dependencies> | |||
| @@ -309,4 +309,56 @@ public class WechatCalllbackController extends BaseController { | |||
| mailService.sendSimpleMail(receivers, titleSB.toString(), sb.toString()); | |||
| } | |||
| } | |||
| @GetMapping(value = "/createOpenPlatform") | |||
| @ApiOperation("创建微信开放平台") | |||
| public String createOpenPlatform(@RequestParam(value="appId") String appId) { | |||
| try { | |||
| String llstr = openService.getWxOpenComponentService().getWxMpServiceByAppid(appId).createOpenPlatform(appId); | |||
| logger.info(llstr); | |||
| return llstr; | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| return null; | |||
| } | |||
| @GetMapping(value = "/bindOpenPlatform") | |||
| @ApiOperation("绑定微信开放平台") | |||
| public String bindOpenPlatform(@RequestParam(value = "appId") String appId, @RequestParam(value = "openAppId") String openAppId) { | |||
| try { | |||
| String llstr = openService.getWxOpenComponentService().getWxMpServiceByAppid(appId).bindOpenPlatform(appId, openAppId); | |||
| logger.info(llstr); | |||
| return llstr; | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| return null; | |||
| } | |||
| @GetMapping(value = "/unbindOpenPlatform") | |||
| @ApiOperation("解绑微信开放平台") | |||
| public String unbindOpenPlatform(@RequestParam(value = "appId") String appId, @RequestParam(value = "openAppId") String openAppId) { | |||
| try { | |||
| String llstr = openService.getWxOpenComponentService().getWxMpServiceByAppid(appId).unbindOpenPlatform(appId, openAppId); | |||
| logger.info(llstr); | |||
| return llstr; | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| return null; | |||
| } | |||
| @GetMapping(value = "/getOpenPlatform") | |||
| @ApiOperation("获取微信开放平台") | |||
| public String getOpenPlatform(@RequestParam(value = "appId") String appId) { | |||
| try { | |||
| String llstr = openService.getWxOpenComponentService().getWxMpServiceByAppid(appId).getBindOpenPlatform(appId); | |||
| logger.info(llstr); | |||
| return llstr; | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| return null; | |||
| } | |||
| } | |||
| @@ -0,0 +1,18 @@ | |||
| package com.iformall.schedule; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import org.springframework.scheduling.annotation.EnableScheduling; | |||
| import org.springframework.scheduling.annotation.SchedulingConfigurer; | |||
| import org.springframework.scheduling.config.ScheduledTaskRegistrar; | |||
| @Configuration | |||
| @EnableScheduling | |||
| public class SchedulingConfig implements SchedulingConfigurer { | |||
| @Override | |||
| public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { | |||
| } | |||
| } | |||
| @@ -0,0 +1,77 @@ | |||
| package com.iformall.schedule; | |||
| import com.iformall.domain.po.WxPayAccount; | |||
| import com.iformall.domain.vo.WxPayOrderVo; | |||
| import com.iformall.mapper.WxPayAccountMapper; | |||
| import com.iformall.mapper.WxPayOrderMapper; | |||
| import com.iformall.service.wechat.WxOpenService; | |||
| import me.chanjar.weixin.open.api.WxOpenMaService; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.scheduling.annotation.Scheduled; | |||
| import org.springframework.stereotype.Component; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @Component | |||
| public class UserUnionIdSchedule { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| private final int TIME_OUT_VALUE = 4 * 60 * 1000; //4分钟 | |||
| @Autowired | |||
| WxPayOrderMapper payOrderMapper; | |||
| @Autowired | |||
| private WxOpenService openService; | |||
| @Autowired | |||
| private WxPayAccountMapper payAccountMapper; | |||
| @Scheduled(cron = "0 */4 * * * *?") // 每4分钟检查一次 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void payOrderGetUnionIdSchedule() { | |||
| Map dateMap = new HashMap(); | |||
| Date curDate = new Date(); | |||
| Date expireDate = new Date(curDate.getTime() - TIME_OUT_VALUE ); | |||
| // 券相关订单 | |||
| dateMap.put("startDate", expireDate); | |||
| List<WxPayOrderVo> paidList = payOrderMapper.findListOfPaidOrderByDate(dateMap); | |||
| paidList.parallelStream().forEach( payOrderVo -> { | |||
| getUnionId(payOrderVo); | |||
| }); | |||
| } | |||
| /** | |||
| * 根据payOrder信息获取UnionId | |||
| * @param payOrderVo | |||
| */ | |||
| public void getUnionId(WxPayOrderVo payOrderVo) { | |||
| if(StringUtils.isBlank(payOrderVo.getOpenId())) { | |||
| return; | |||
| } | |||
| try { | |||
| // code提交 | |||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(payOrderVo.getAppId()); | |||
| if(StringUtils.isNotBlank(payOrderVo.getTransactionId())) { | |||
| String openRet = openMaService.getApiGetPaidUnionid(payOrderVo.getOpenId(), payOrderVo.getTransactionId()); | |||
| logger.info(openRet); | |||
| } else { | |||
| WxPayAccount payAccount = payAccountMapper.selectByPrimaryKey(payOrderVo.getPayId()); | |||
| if(payAccount != null) { | |||
| String openRet = openMaService.getApiGetPaidUnionid(payOrderVo.getOpenId(), payAccount.getMchId(), payOrderVo.getPayOrderNo()); | |||
| logger.info(openRet); | |||
| } | |||
| } | |||
| }catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| @@ -28,10 +28,10 @@ | |||
| </parent> | |||
| <properties> | |||
| <weixin-java-common.version>3.3.0</weixin-java-common.version> | |||
| <weixin-java-mp.version>3.3.0</weixin-java-mp.version> | |||
| <weixin-java-miniapp.version>3.3.0</weixin-java-miniapp.version> | |||
| <weixin-java-pay.version>3.3.0</weixin-java-pay.version> | |||
| <weixin-java-common.version>3.3.0.A</weixin-java-common.version> | |||
| <weixin-java-mp.version>3.3.0.A</weixin-java-mp.version> | |||
| <weixin-java-miniapp.version>3.3.0.A</weixin-java-miniapp.version> | |||
| <weixin-java-pay.version>3.3.0.A</weixin-java-pay.version> | |||
| <quartz.version>2.3.0</quartz.version> | |||
| </properties> | |||