Browse Source

微信第三方平台-修改

dev_shibei_match
zxc 5 years ago
parent
commit
b0e8c6724f
  1. 2
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CustomerMpDao.java
  2. 81
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java
  3. 1
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml
  4. 2
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/BindingAccountDao.xml
  5. 4
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/CustomerMpDao.xml
  6. 4
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/OpenFlatformAccountDao.xml

2
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/CustomerMpDao.java

@ -58,7 +58,7 @@ public interface CustomerMpDao extends BaseDao<CustomerMpEntity> {
* @param customerId
* @author zxc
*/
Integer selectAuthCount(@Param("customerId")String customerId);
List<String> selectAuthCount(@Param("customerId")String customerId);
/**
* @Description 回填customer_mp的appId

81
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ComponentVerifyTicketServiceImpl.java

@ -143,7 +143,8 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
AuthCodeResultDTO authCodeResultDTO = authorizationInfoDao.selectCustomerIdByAuthAppId(authAppId);
String clientType = authCodeResultDTO.getClientType();
String customerId = authCodeResultDTO.getCustomerId();
this.updateCustomerMpAppIdAndCreateOpenPlatform(customerId,authAppId,clientType);
this.createAndBindOpenAccount(customerId,authAppId,clientType);
this.updateCustomerMpAppId(customerId,authAppId,clientType);
authCodeDao.updateAppId(customerId,clientType,authAppId);
this.saveAuthAccountInfo(customerId,authAppId,clientType);
break;
@ -495,7 +496,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
* @author zxc
*/
@Transactional(rollbackFor = Exception.class)
public void updateCustomerMpAppIdAndCreateOpenPlatform(String customerId,String authAppId,String clientType){
public void updateCustomerMpAppId(String customerId,String authAppId,String clientType){
log.info("==========回填customer_mp开始==========");
AuthCodeFormDTO formDTO = new AuthCodeFormDTO();
formDTO.setClientType(clientType);
@ -506,6 +507,82 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe
log.info("==========回填customer_mp结束==========");
}
public void createAndBindOpenAccount(String customerId,String authAppId,String clientType){
log.info("开始创建开放平台账号并绑定");
List<String> authCount = customerMpDao.selectAuthCount(customerId);
String openPlatformId = null;
if (authCount.size()>0){
openPlatformId = openPlatformAccountDao.selectOpenAppIdByCustomerId(customerId);
}
Map<String, Object> authorizerRefreshToken = redisThird.getAuthorizerRefreshToken(customerId + ThirdRedisKeyConstant.COLON + clientType);
String authorizerAccessToken = authorizerRefreshToken.get("authorizerAccessToken").toString();
if (authCount.size()==NumConstant.ZERO){
log.info("未查询到该客户授权信息,先创建开放平台账号,再绑定");
//没有任何一个小程序/公众号授权,【先创建,再绑定】
JSONObject jsonObject = new JSONObject();
jsonObject.put(ModuleConstant.LOW_APP_ID,authAppId);
// 此处的 access_token 为 【authorizer_access_token】
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_CREATE_OPEN + authorizerAccessToken, JSON.toJSONString(jsonObject)).getData();
Map<String,Object> map = JSON.parseObject(data, Map.class);
openPlatformId = map.get(ModuleConstant.OPEN_APP_ID).toString();
CreateOpenResultDTO createOpen = new CreateOpenResultDTO();
createOpen.setErrCode((Integer)map.get(ModuleConstant.ERR_CODE));
createOpen.setErrMsg(map.get(ModuleConstant.ERR_MSG).toString());
createOpen.setOpenAppId(map.get(ModuleConstant.OPEN_APP_ID).toString());
switch (createOpen.getErrCode()){
case NumConstant.ZERO:
log.info(CREATE_AND_BIND_SUCCESS);
CreateOpenFormDTO coForm = new CreateOpenFormDTO();
coForm.setOpenid(map.get(ModuleConstant.OPEN_APP_ID).toString());
coForm.setCustomerId(customerId);
//插入 open_platform_account 表
openPlatformAccountDao.insertOpenPlatFormAccount(coForm);
break;
case NumConstant.ONE_NEG:
throw new RenException(SYSTEM_ERROR);
case ModuleConstant.FORTY_THOUSAND_AND_THIRTEEN:
throw new RenException(INVALID_APP_ID);
case ModuleConstant.EIGHTY_NINE_THOUSAND:
throw new RenException(ACCOUNT_HAS_BOUND_OPEN);
}
}else if (authCount.size()>NumConstant.ZERO && !authCount.contains(authAppId)){
log.info("该客户已创建过开放平台账号,直接绑定");
JSONObject jsonObject = new JSONObject();
jsonObject.put(ModuleConstant.LOW_APP_ID,authAppId);
jsonObject.put(ModuleConstant.OPEN_APP_ID,openPlatformId);
String data = HttpClientManager.getInstance().sendPostByJSON(WxMaCodeConstant.API_BIND_OPEN + authorizerAccessToken, JSON.toJSONString(jsonObject)).getData();
Map<String,Object> map = JSON.parseObject(data, Map.class);
CreateOpenResultDTO createOpen = new CreateOpenResultDTO();
createOpen.setErrCode((Integer)map.get(ModuleConstant.ERR_CODE));
createOpen.setErrMsg(map.get(ModuleConstant.ERR_MSG).toString());
switch (createOpen.getErrCode()){
case NumConstant.ZERO:
log.info(BIND_SUCCESS);
break;
case NumConstant.ONE_NEG:
throw new RenException(SYSTEM_ERROR);
case ModuleConstant.FORTY_THOUSAND_AND_THIRTEEN:
throw new RenException(INVALID_APP_ID);
case ModuleConstant.EIGHTY_NINE_THOUSAND:
throw new RenException(ACCOUNT_HAS_BOUND_OPEN);
case ModuleConstant.EIGHTY_NINE_THOUSAND_AND_ONE:
throw new RenException(NOT_SAME_CONTRACTOR);
case ModuleConstant.EIGHTY_NINE_THOUSAND_AND_THREE:
throw new RenException(NOT_ALLOWED_OPERATE);
case ModuleConstant.EIGHTY_NINE_THOUSAND_AND_FOUR:
throw new RenException(TO_LIMIT);
}
}
//插入 binding_account
BindingAccountFormDTO bindingAccount = new BindingAccountFormDTO();
bindingAccount.setOpenPlatformAccountId(openPlatformId);
bindingAccount.setAuthAppId(authAppId);
bindingAccount.setClientType(clientType);
bindingAccount.setCustomerId(customerId);
bindingAccountDao.insertBindingAccount(bindingAccount);
log.info("创建绑定账号结束");
}
/**
* @Description map Entity
* @param map

1
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/AuthorizationInfoDao.xml

@ -68,6 +68,7 @@
<update id="updateOldAuthorizerAccessToken">
update authorization_info set del_flag = 1 where customer_id = #{customerId} AND client_type = #{clientType}
</update>
<select id="getAuthInfoByCustomer" resultType="com.epmet.dto.AuthorizationInfoDTO">
SELECT AUTHORIZER_APPID,
AUTHORIZER_ACCESS_TOKEN

2
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/BindingAccountDao.xml

@ -15,7 +15,7 @@
#{clientType},
#{delFlag},
#{revision},
#{createDBy},
#{createdBy},
NOW(),
#{updatedBy},
NOW()

4
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/CustomerMpDao.xml

@ -19,9 +19,9 @@
client ASC
</select>
<!-- 查询授权的数量 -->
<select id="selectAuthCount" resultType="java.lang.Integer">
<select id="selectAuthCount" resultType="java.lang.String">
SELECT
COUNT(*) AS notAuthCount
app_id AS authAppId
FROM
customer_mp
WHERE

4
epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/OpenFlatformAccountDao.xml

@ -12,7 +12,7 @@
VALUES
(
REPLACE ( UUID(), '-', '' ),
#{openAppId},
#{openid},
#{customerId},
#{delFlag},
#{revision},
@ -28,7 +28,7 @@
SELECT
open_app_id AS openAppId
FROM
open_flatform_account
open_platform_account
WHERE
del_flag = 0
AND customer_id = #{customerId}

Loading…
Cancel
Save