多平台多渠道账号体系绑定第一篇-微信小程序篇

先奉上本篇实现效果

多平台多渠道账号体系绑定第一篇-微信小程序篇

近来,在对接三方平台时,欲将多方开放平台统一整合入笔者的框架内。

如下为大致思路设计图

在这里插入图片描述
由于需对接多方平台关联账号体系,思来之后,将设计一张“三方平台中间表”。

表结构如下:

在这里插入图片描述

在此,将主要字段赘述一下:

platform_code:三方平台的编码,例(微信小程序、QQ小程序、微信App、百度小程序等一些三方平台),当然,笔者也会预留对应的接口,供自定义三方平台对接,实现着可在自由的业务代码中实现。

app_channel_code:应用渠道编码,为满足同一个渠道中发行了多个应用版本,故而作此区分。

表结构设计完毕,自然要与账号表进行关联,关联图如下:
在这里插入图片描述
既,表已设计完毕,此下将具体实现功能。

由于需要对接三方平台,笔者先定义一些小程序渠道的字典,后期再扩展其他三方渠道。

/**
 * 三方平台类型
 */
@DictionaryConfig(dictionaryCode = PlatformType.DICTIONARY_CODE, dictionaryName = "三方平台类型", remark = "三方平台类型", version = 4)
public static class PlatformType {
   

    public static final String DICTIONARY_CODE = "2101";
    /*==================小程序渠道================*/
    /**
     * QQ小程序
     */
    @DictionaryConfig(dictionaryName = "QQ小程序", remark = "QQ小程序")
    public static final String MP_QQ = "210101";
    /**
     * 微信小程序渠道
     */
    @DictionaryConfig(dictionaryName = "微信小程序", remark = "微信小程序")
    public static final String MP_WEIXIN = "210102";
    /**
     * 支付宝小程序
     */
    @DictionaryConfig(dictionaryName = "支付宝小程序", remark = "支付宝小程序")
    public static final String MP_ALIPAY = "210103";
    /**
     * 百度小程序
     */
    @DictionaryConfig(dictionaryName = "百度小程序", remark = "百度小程序")
    public static final String MP_BAIDU = "210104";
    /**
     * 头条小程序
     */
    @DictionaryConfig(dictionaryName = "头条小程序", remark = "头条小程序")
    public static final String MP_TOUTIAO = "210105";
    /**
     * 360小程序
     */
    @DictionaryConfig(dictionaryName = "360小程序", remark = "360小程序")
    public static final String MP_360 = "210106";
    /*==================小程序渠道================*/
}

因需对接多方不同渠道平台,故笔者先定义一套接口,制定规范。

package com.threeox.biz.account.platform.inter;

import com.threeox.biz.account.entity.AccountPlatformInfo;
import com.threeox.biz.account.platform.entity.AccessToken;
import com.threeox.drivenlibrary.engine.entity.driven.config.OpenPlatformConfigMessage;
import com.threeox.drivenlibrary.manage.entity.params.AuthorizedLoginParams;
import com.threeox.biz.account.platform.entity.PhoneInfo;

/**
 * 开放平台接口
 *
 * @author 赵屈犇
 * @version 1.0
 * @date 创建时间: 2022/1/17 10:33
 */
public interface IOpenPlatform {
   


    /**
     * 获取手机信息
     *
     * @param params 授权登录的参数
     * @return a
     * @author 赵屈犇
     * @date 创建时间: 2022/6/23 23:13
     * @version 1.0
     */
    PhoneInfo getPhoneInfo(AuthorizedLoginParams params) throws Exception;

    /**
     * 获取三方平台对象
     *
     * @param params  授权登录的参数
     * @return a
     * @author 赵屈犇
     * @date 创建时间: 2022/6/22 23:29
     * @version 1.0
     */
    AccountPlatformInfo getOpenInfo(AuthorizedLoginParams params) throws Exception;

    /**
     * 获取授权凭证对象
     *
     * @param openPlatform
     * @return a
     * @author 赵屈犇
     * date 创建时间: 2022/6/25 00:44
     * @version 1.0
     */
    AccessToken getAccessToken(OpenPlatformConfigMessage openPlatform) throws Exception;

}

基于本接口实现基础的开发平台工厂类

package com.threeox.biz.account.platform.impl.base;

import com.threeox.biz.account.entity.AccountPlatformInfo;
import com.threeox.biz.account.platform.entity.AccessToken;
import com.threeox.biz.account.platform.entity.PhoneInfo;
import com.threeox.biz.account.platform.inter.IOpenPlatform;
import com.threeox.drivenlibrary.engine.config.DrivenEngineConfig;
import com.threeox.drivenlibrary.engine.entity.driven.config.OpenPlatformConfigMessage;
import com.threeox.drivenlibrary.manage.cache.account.AccessTokenCacheManager;
import com.threeox.drivenlibrary.manage.entity.params.AuthorizedLoginParams;
import com.threeox.utillibrary.ConstUtils;
import com.threeox.utillibrary.date.DateUtil;
import com.threeox.utillibrary.date.TimeUtils;
import com.threeox.utillibrary.logger.LoggerFactory;
import com.threeox.utillibrary.strings.StringUtils;

/**
 * 基础开放平台类
 *
 * @author 赵屈犇
 * @version 1.0
 * @date 创建时间: 2022/1/16 11:39
 */
public abstract class BaseOpenPlatformFactory implements IOpenPlatform {
   

    /**
     * 日志对象
     */
    protected final LoggerFactory looger = LoggerFactory.getLogger(this.getClass().getName());

    @Override
    public PhoneInfo getPhoneInfo(AuthorizedLoginParams params) throws Exception {
   
        OpenPlatformConfigMessage openPlatform = getOpenPlatform(params);
        if (openPlatform != null) {
   
            return initPlatformPhoneInfo(params, openPlatform);
        }
        return null;
    }

    /**
     * 初始化平台手机信息
     *
     * @param params
     * @param openPlatform
     * @return a
     * @author 赵屈犇
     * @date 创建时间: 2022/6/23 23:18
     * @version 1.0
     */
    protected abstract PhoneInfo initPlatformPhoneInfo(AuthorizedLoginParams params, OpenPlatformConfigMessage openPlatform) throws Exception;

    @Override
    public AccountPlatformInfo getOpenInfo(AuthorizedLoginParams params) throws Exception {
   
        // 根据应用渠道编码获取配置的开放渠道信息
        OpenPlatformConfigMessage openPlatform = getOpenPlatform(params);
        if (openPlatform != null) {
   
            AccountPlatformInfo platformInfo = new AccountPlatformInfo();
            platformInfo.setPlatformCode(params.getPlatformCode());
            platformInfo.setAppChannelCode(params.getAppChannelCode());
            // 子类实现三方平台账号主键获取
            initPlatformOpenId(params, openPlatform, platformInfo);
            return platformInfo;
        }
        return null;
    }

    /**
     * 设置三方平台账号主键
     *
     * @param params
     * @param openPlatform
     * @param platformInfo
     * @return a
     * @author 赵屈犇
     * @date 创建时间: 2022/6/22 23:54
     * @version 1.0
     */
    prote
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值