JAVA版B2B2C商城源码多商家入驻商城系统微信小程序直播带货新零售商城...

JAVA版B2B2C商城源码多商家入驻商城系统微信小程序直播带货新零售商城...

2023年7月2日发(作者:)

JAVA版B2B2C商城源码多商家⼊驻商城系统微信⼩程序直播带货新零售商城o2o商城 @源码地址来源: /honghu2/微信⼩程序登录代码:/** * Copyright © 2012-2017 HongHu All rights reserved. */package ller;

import ortedEncodingException;import oder;import thmParameters;import ty;import ist;import ;import ;import p;import ;import ;import r;import n;

import ;import meterSpec;import KeySpec;import rvletRequest;

import Utils;import 64;import ;import Factory;import ils;import red;import tBody;import tMapping;import tMethod;import tParam;import ntroller;

import CastleProvider;import ;import ;import seCode;import s;import oryDto;import tDto;import to;import figDto;import o;import oryFeignClient;import butionUserFeignClient;import eFeignClient;import tFeignClient;import eignClient;import figFeignClient;import tIMFeignClient;import tIMFeignClient;import til;import ervice;import tyUserHolder;import ;import il;import ions;import ientUtils;import ;import 5Encrypt;

import 4j;import ject;

/** * 微信⼩程序登录Controller * @author Administrator * */@Slf4j@RestController@RequestMapping(value = "/weChat")public class WeChatLoginController {

@Autowired private IUserService userService; @Autowired private RedisUtil redisUtil; @Autowired private SysConfigFeignClient sysConfigFeignClient; @Autowired private DistributionUserFeignClient disUserFeignClient; @Autowired private FtpFileFeignClient ftpFileFeignClient; @Autowired private TencentIMFeignClient tencentIMFeignClient; @Autowired private StoreFeignClient storeFeignClient; @Autowired private PaymentFeignClient paymentFeignClient;/* @Autowired private AccessoryFeignClient accessoryFeignClient;*/

private static final Logger logger = ger();

/***微信获取登录凭证url***/ private static final String CODE2SESSION_URL = "/sns/jscode2session";

/** * ⼩程序登录 * @param js_code 登录code * @param iv 加密算法的初始向量 * @param encryptedData 敏感⽤户数据 * @param share_uid 邀请注册⽤户 * @return */ @RequestMapping(value = "/login", method = ) public Map login(@RequestBody JSONObject json) { String js_code = ing("js_code"); String iv = ing("iv"); String encryptedData = ing("encryptedData"); String share_uid = ing("share_uid"); String source_type = ing("source_type"); String nickName = ing("nickName"); String userphoto = ing("photo"); /*SysConfigDto sysConfigDto = Config(); String appid = n_weixin_appId();

String secret = n_weixin_appSecret();*/

// 微信APPID、微信密匙 Map param = hMap(); ("mark", "wx_miniprogram"); List payments = ageList(param); PaymentDto payment =null; if (() > 0) { payment = (PaymentDto) (0); } if (payment==null||y(_appid()) || y(_appSecret())) { return odeMap("40031", "获取微信配置信息有误!", null); } Map params = new HashMap(); ("appid", _appid()); ("secret", _appSecret()); ("js_code", js_code); ("grant_type", "authorization_code"); String jsonStr = (CODE2SESSION_URL, params, "UTF-8"); JSONObject jsonObj = ject(jsonStr);

// 错误码 String errcode = ing("errcode"); if((errcode, "40028")){ // code ⽆效 return odeMap("40028", "code ⽆效!", null); }

// errcode[-1:系统繁忙,此时请开发者稍候再试;45011:频率限制,每个⽤户每分钟100次] if((errcode, "45011") || (errcode, "-1")){ return odeMap("45011", "系统繁忙,请稍后再试!", null); }

String session_key = ing("session_key"); String openid = ing("openid"); // 会话密钥和⽤户唯⼀标识为空,表⽰服务请求失败,记录⽇志 if(y(session_key) || y(openid)){ return odeMap("40029", "code⽆效!", null); }

// 解析⼩程序加密⽤户数据 String userInfo = t(_appid(), encryptedData, session_key, iv); if(y(userInfo)){ return odeMap("40030", "获取⽤户数据失败!", null); } JSONObject userJson = ject(userInfo); // 开放平台的唯⼀标识符 String unionid = ing("unionId"); if(y(unionid)){ return odeMap("40032", "获取⽤户数据失败!", null); }

boolean phone=false; User user=null; boolean flag = false; //true 则不需要授权⼿机号 // 根据开放平台的唯⼀标识签,查询⽤户对象是否存在,不存在注册⼀条数据 synchronized (this) { user = ByUnionid(unionid); if(user != null && urity() == 1){ return odeMap("40031", "账户存在安全隐患禁⽌登录!", null); } if (user!=null&&rname()!=null&&lank(ile())) { phone=true; } if(user == null){ flag = true; user = new User(); nId(openid); if (mpty(nickName)) { kName(nickName); }else{ kName(ing("nickName")); //微信提供的默认头像 } xin_unionID(unionid); _msg_count(0);

eteStatus(0); Time(new Date()); sword(5("123456").toLowerCase());//设置默认密码为123456 rs(0); // ⽤户年龄 _live(0); e_code(MaxLiveCode() + 1); r_type(0); // ⽤户类别,默认为0个⼈⽤户,1为企业⽤户 re_apply_step(0); // 店铺申请进⾏的步骤,默认为0 oiceType(0); // 发票类型 ther_attention(1); //是否允许关注 0为不允许,1为允许 r_form("miniProgram"); //注册来源,分为pc,android,ios,miniProgram, WXOffiaccount if (mpty(source_type)) { rce_type(2Int(source_type)); //1为海报 } tity(user); user = ByUnionid(unionid); }else if((r_form(), "WXOffiaccount") && k(nId())){ //通过微信公众号注册的 nId(openid); ById(user); flag = true; //微信注册第⼀次进来分销关系重新建⽴ } }

boolean isUpdate=false; // 处理⽤户头像(⽤户头像不存在,将微信的头像保存到⽤户头像) //String photo_url = ing("avatarUrl"); if(to_id() == null && mpty(userphoto)){ AccessoryDto photo = uploadPhotoFile(userphoto, ()); if(photo != null){ to(photo); to_id(()); isUpdate=true; } } //⽤户换名称或头像 if(kName()==null){ kName(nickName); isUpdate=true; } if (e_code()==null) { e_code(MaxLiveCode() + 1); isUpdate=true; } if (mpty(nickName) && y(kName())) { kName(nickName); isUpdate = true; } if (y(nId())) { nId(openid); isUpdate = true; } if (isUpdate) { ById(user); } //所有⽤户都是分销⽤户 if(flag){ sUser(user, share_uid); } // ⽣成token,格式:⽤户id;时间戳

String token = (() + ";" + tTimeMillis()+";"+"small", 0); // 将token存到redis中,有效期24⼩时

(_LOGIN_MARK + (), token, _INFO_EXPIRE_TIME);

// 覆盖redis⽤户信息 UserDto userDto = new UserDto(); operties(user, userDto); (_INFO_MARK + (), userDto, _INFO_EXPIRE_TIME);

String storestatus=""; if (re_id()!=null) { StoreDto storeDto = ByPrimaryKey(re_id()); if (storeDto!=null) { storestatus=re_status()+""; } } HashMap result = new HashMap<>(); ("token", token); ("storestatus", storestatus); SysConfigDto sysConfig = Config(); if (n_live()==0) { ("phone", true); }else{ ("phone", phone); }

("session_key", session_key); ("user", user);

if (user != null&&_live()!=null) { ("is_live", _live()==2?true:false); }else{ ("is_live", false); } return uccessMap(result); }

/** * 保存⽤户⼿机号 * @return */ @RequestMapping(value = "/savePhone", method = ) public Map savePhone(HttpServletRequest request, @RequestBody JSONObject json) { String session_key = ing("session_key"); String iv = ing("iv"); String encryptedData = ing("encrypData");

if (k(session_key)) { return ailMap("获取失败,session_key信息错误", null);

} if (k(iv)) { return ailMap("获取失败,iv信息错误", null);

} if (k(encryptedData)) { return ailMap("获取失败,encryptedData信息错误", null);

} byte[] dataByte = (encryptedData); // 加密秘钥 byte[] keyByte = (session_key); // 偏移量 byte[] ivByte = (iv); try { // 如果密钥不⾜16位,那么就补⾜. 这个if 中的内容很重要 int base = 16; if ( % base != 0) { int groups = / base + ( % base != 0 ? 1 : 0); byte[] temp = new byte[groups * base]; (temp, (byte) 0); opy(keyByte, 0, temp, 0, ); keyByte = temp; } // 初始化 vider(new BouncyCastleProvider()); Cipher cipher = tance("AES/CBC/PKCS5Padding"); SecretKeySpec spec = new SecretKeySpec(keyByte, "AES"); AlgorithmParameters parameters = tance("AES"); (new IvParameterSpec(ivByte)); (T_MODE, spec, parameters);// 初始化 byte[] resultByte = l(dataByte); if (null != resultByte && > 0) { String result = new String(resultByte, "UTF-8");

JSONObject fromObject = ject(result); Object object = ("purePhoneNumber"); User user = ByPrimaryKey(rentUserId(request)); //查询是否已经存在该⼿机号 User UserName = ByUserName(2String(object));

//需要合并⽤户 , ⼿机号存在, 并且 unionid 为空

if (UserName!=null&&y(xin_unionID())) {

xin_unionID(xin_unionID()); //将新unionid 存⼊旧数据中 if (e_code()==null) { e_code(MaxLiveCode() + 1); } if (y(kName())) { kName(kName()); } if (to_id()!=null) { to_id(to_id()); } if (nId()!=null) { nId(nId()); } if (_open_id()!=null) { _open_id(_open_id());; } ById(UserName); eteStatus(1); ile("del"+2String(object)); rName("del"+2String(object)); xin_unionID("del"+()+""); ById(user); ByUserId(()); //删除新的 分销关系表 (_LOGIN_MARK + ()); //换⽤户登录 // ⽣成token,格式:⽤户id;时间戳

String token = (() + ";" + tTimeMillis()+";"+"small", 0); // 将token存到redis中,有效期24⼩时

(_LOGIN_MARK + (), token, _INFO_EXPIRE_TIME);

// 覆盖redis⽤户信息 UserDto userDto = new UserDto(); operties(UserName, userDto); (_INFO_MARK + (), userDto, _INFO_EXPIRE_TIME); return uccessMap(token);

} //删除

/*//⼿机号跟原来⼀致, 直接通过 if (2String(object).equals(rName())) { return uccessMap("isOk"); }*/ //⼿机号已存在 if (UserName!=null) { return ailMap("⼿机号已存在", "false"); } rName(2String(object)); ile(2String(object)); ById(user); return uccessMap(null); } } catch (Exception e) { tackTrace(); } return ailMap("信息有误", "false"); }

/** * 分享邀请⽤户注册的分享链接 * @return */ @RequestMapping(value = "/shareLogin", method = ) public Map shareLogin( HttpServletRequest request) { UserDto user = rentUser(request); if(user == null || () == null){ return numMap(_EXPIRE, null); } return uccessMap(()); } /** * 分享邀请⽤户注册的分享链接 * @return */ @RequestMapping(value = "/checkUserPhone", method = ) public Map checkUserPhone( HttpServletRequest request) { UserDto user = rentUser(request); if(user == null || () == null){ return numMap(_EXPIRE, null); } User new_user = ByPrimaryKey(()); if (new_ile()==null||new_rName()==null) { return numMap(SE_CODE_USER_MOBILE_OR_TELEPHONE_NOT_EMPTY, null); } return uccessMap(null); }

/** * 分享邀请⽤户购买商品的分享链接 * @return */ @RequestMapping(value = "/shareGoods", method = ) public Map shareGoods( HttpServletRequest request) { UserDto user = rentUser(request); UserDto user = rentUser(request); if(user == null || () == null){ return numMap(_EXPIRE, null); } return uccessMap(()); }

/** * @Description 将字符串中的emoji表情转换成可以在utf-8字符集数据库中保存的格式(表情占4个字节,需要utf8mb4字符集) * @param str * 待转换字符串 * @return 转换后字符串 * @throws UnsupportedEncodingException * exception */ public static String emojiConvert1(String str) { String patternString = "([x{10000}-x{10ffff}ud800-udfff])"; Pattern pattern = e(patternString); Matcher matcher = r(str); StringBuffer sb = new StringBuffer(); while (()) { try { Replacement(sb, "[[" + ((1), "UTF-8") + "]]"); } catch (Exception e) { } } Tail(sb); return ng(); }

/** * 微信授权登录上传头像 * @param photo_url * @param user_id * @return */ public AccessoryDto uploadPhotoFile(String photo_url, Long user_id){ try { AccessoryDto accessoryDto = ("user/image", "", "JPG", user_id, photo_url); return accessoryDto; } catch (Exception e) { ("微信授权登录上传头像失败:"+ckTraceAsString(e)); } return null; }

/** * 将全部的⽤户注册IM账号 * @return */ @RequestMapping(value = "/IM/outImportMultipleAccounts", method = ) public boolean outImportMultipleAccounts() { //获取所有⽤户的信息 Map params = new HashMap(); ("deleteStatus", "0"); int count = Count(params); int pageNum = (count/100)+1; //腾讯只⽀持最多100个账号删除 boolean bol = true; for(int i = 1; i <= pageNum; i++){ ("currentPage", i); ("pageSize", 100); ("pageSize", 100); List list = ages(params); List uids = new ArrayList(); for (User user : list) { (().toString()); } bol = MultipleAccounts(uids); } return bol; }

/** * 将全部的⽤户注册IM账号 * @return */ @RequestMapping(value = "/IM/outAccountDelete", method = ) public boolean outAccountDelete() { //获取所有⽤户的信息 Map params = new HashMap(); ("deleteStatus", "0"); int count = Count(params); int pageNum = (count/100)+1; //腾讯只⽀持最多100个账号删除 boolean bol = true; for(int i = 1; i <= pageNum; i++){ ("currentPage", i); ("pageSize", 100); List list = ages(params); List uids = new ArrayList(); for (User user : list) { (().toString()); } bol = tDelete(uids); } return bol; }

/** * 微信授权登录 * @param code 授权临时票据 * @return map * @throws Exception */ @RequestMapping(value = "/weChatLogin" , method = ) public Map weChatLogin(@RequestParam("code") String code) throws Exception { return Login(code); } /** * 微信授权登录(uniapp使⽤) * @param code 授权临时票据 * @return map * @throws Exception */ @RequestMapping(value = "/appWeChatLogin" , method = ) public Map appWeChatLogin(@RequestBody JSONObject json) throws Exception { return hatLogin(json); } @RequestMapping(value = "/appWeChatLoginNew" , method = ) public Map appWeChatLoginNew(@RequestBody JSONObject json) throws Exception { return hatLoginNew(json); }

/** * 微信授权登录 * @param code 授权临时票据 * @return map * @return map * @throws Exception */ @RequestMapping(value = "/weChatH5Login" , method = ) public Map weChatH5Login(@RequestParam("code") String code) throws Exception { return H5Login(code); }

}@源码地址来源: /honghu2/

发布者:admin,转转请注明出处:http://www.yc00.com/web/1688279231a112494.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信