国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

uni-app +java小程序端對(duì)接微信登陸

這篇具有很好參考價(jià)值的文章主要介紹了uni-app +java小程序端對(duì)接微信登陸。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

一:前期準(zhǔn)備

要想實(shí)現(xiàn)微信登陸,首先必須注冊(cè)開發(fā)者賬號(hào)。

  • 登錄微信開放平臺(tái),添加移動(dòng)應(yīng)用并提交審核,審核通過后可獲取應(yīng)用ID(AppID),AppSecret等信息
  • 在應(yīng)用詳情中申請(qǐng)開通微信登錄功能,根據(jù)頁面提示填寫資料,提交審核
  • 申請(qǐng)審核通過后即可打包使用微信授權(quán)登錄功能

二:實(shí)現(xiàn)思路

1.app端請(qǐng)求調(diào)用微信登陸,用戶登陸授權(quán)之后會(huì)返回一個(gè)code,通過這個(gè)code加上appid和????????appSecret和可以得到access_tokenopenid等信息,通過access_tokenopenid 我們就可以去查詢到用戶基本登陸信息了。

uni-app +java小程序端對(duì)接微信登陸

?三:具體實(shí)現(xiàn)

1.配置

在Hbulidx工具里打開uniapp項(xiàng)目,找到

manifest.json文件,在“App模塊配置”項(xiàng)的“OAuth(登錄鑒權(quán))”下,勾選“微信登錄”:?

uni-app +java小程序端對(duì)接微信登陸

  • appid
    微信開放平臺(tái)申請(qǐng)應(yīng)用的AppID值
  • appSecret(HBuilderX3.4.18+ 不再提供此參數(shù)的可視化配置,詳見配置參數(shù)安全性問題)
    微信開放平臺(tái)申請(qǐng)應(yīng)用的AppSecret值
  • UniversalLinks
    iOS平臺(tái)通用鏈接,必須與微信開放平臺(tái)配置的一致,推薦使用一鍵生成iOS通用鏈接

?2.前端代碼

<template>
	<view class="content">
		<view class="text-area">
			<button @click="wxlogin">微信登陸</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {

		},
		methods: {
			wxlogin() {
				   
				   uni.login({
				     provider: 'weixin', //使用微信登錄
					// onlyAuthorize: true,
				     success: function (loginRes) {
				       console.log(loginRes.authResult);
					   console.log("loginRes.authResult.accessToken="+loginRes.authResult.access_token)
					   uni.request({
					   		    url: 'http://192.168.1.9:8085/wx/login', //僅為示例,并非真實(shí)接口地址。
					   			method:'GET',
					   		    data: {
					   		       accessToken:loginRes.authResult.access_token,
					   		       openid:loginRes.authResult.openid,
					   		    },
					   		    
					   		});
					  },					   	
					   
					  })
				   
					

			}
		},
		
		 
	}
	
</script>

<style>

</style>

這里就簡單展示一下,效果圖:

uni-app +java小程序端對(duì)接微信登陸

點(diǎn)擊登陸后就會(huì)自動(dòng)跳轉(zhuǎn)到微信登陸授權(quán)頁面了。

3.后端代碼

1.WechatTokenEntity類

package com.jdzh.enterprise.wxlogin;


/**
 * 描述: 憑證 </br>
 * 發(fā)布版本:V1.0 </br>
 */
public class WechatTokenEntity {
    /**
     * 接口訪問憑證?
     */
    private String accessToken;
    /**
     * 接口訪問憑證?,刷新
     */
    private String refreshToken;
    /**
     * 憑證有效期單位:second
     */
    private int expiresIn;
    /**
     * 授權(quán)用戶唯一標(biāo)識(shí)
     */
    private String openid;
    /**
     * 微信用戶唯一標(biāo)識(shí)
     */
    private String unionId;

    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public int getExpiresIn() {
        return expiresIn;
    }

    public void setExpiresIn(int expiresIn) {
        this.expiresIn = expiresIn;
    }

    public String getUnionId() {
        return unionId;
    }

    public void setUnionId(String unionId) {
        this.unionId = unionId;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }
}

2.WechatTrustManager類

package com.jdzh.enterprise.wxlogin;


import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;

/**
 * 描述:信任管理器 </br>
 * 發(fā)布版本:V1.0 </br>
 */
/*
 * 證書管理器的作用是讓它新人我們指定的證書,
 * 此類中的代碼意味著信任所有的證書,不管是不是權(quán)威機(jī)構(gòu)頒發(fā)的。
 */
public class WechatTrustManager implements X509TrustManager {
    // 檢查客戶端證書
    public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
    }

    // 檢查服務(wù)器端證書
    public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
    }

    // 返回受信任的X509證書數(shù)組
    public X509Certificate[] getAcceptedIssuers() {
        return null;
    }
}

3.WechatUserEntity

package com.jdzh.enterprise.wxlogin;


import java.io.Serializable;

/**
 * 用戶管理InfoVO
 *
 * @author es
 * @email es@126.com
 */
public class WechatUserEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 用戶的標(biāo)識(shí)
     */
    private String openId;
    /**
     * 關(guān)注狀態(tài)(1是關(guān)注,0是未關(guān)注),未關(guān)注時(shí)獲取不到其余信息
     */
    private int subscribe;
    /**
     * 用戶關(guān)注時(shí)間,為時(shí)間戳。如果用戶曾多次關(guān)注,則取最后關(guān)注時(shí)間
     */
    private String subscribeTime;
    /**
     * 昵稱
     */
    private String nickname;
    /**
     * 用戶的性別(1是男性,2是女性,0是未知)
     */
    private int sex;
    /**
     * 用戶所在國家
     */
    private String country;
    /**
     * 用戶所在省份
     */
    private String province;
    /**
     * 用戶所在城市
     */
    private String city;
    /**
     * 用戶的語言,簡體中文為zh_CN
     */
    private String language;
    /**
     * 用戶頭像
     */
    private String headImgUrl;
    /**
     * 用戶特權(quán)信息
     */
    private String PrivilegeList;
    /**
     * 微信授權(quán)用戶唯一標(biāo)識(shí)
     */
    private String unionId;

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public int getSubscribe() {
        return subscribe;
    }

    public void setSubscribe(int subscribe) {
        this.subscribe = subscribe;
    }

    public String getSubscribeTime() {
        return subscribeTime;
    }

    public void setSubscribeTime(String subscribeTime) {
        this.subscribeTime = subscribeTime;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public String getHeadImgUrl() {
        return headImgUrl;
    }

    public void setHeadImgUrl(String headImgUrl) {
        this.headImgUrl = headImgUrl;
    }

    public String getPrivilegeList() {
        return PrivilegeList;
    }

    public void setPrivilegeList(String privilegeList) {
        PrivilegeList = privilegeList;
    }

    public String getUnionId() {
        return unionId;
    }

    public void setUnionId(String unionId) {
        this.unionId = unionId;
    }
}

4.WechatUtils

package com.jdzh.enterprise.wxlogin;



import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class WechatUtils {
    private final static Logger log = LoggerFactory.getLogger(WechatUtils.class);
    private final static String appid = "appid"; //憑證
    private final static String appsecret = "appsecret"; //憑證密鑰

    // 憑證獲?。℅ET)
    public final static String tokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
    //userinfo
    public final static String userInfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";

    /**
     * 獲取接口訪問憑證
     *
     * @param code app授權(quán)后傳回
     * @return
     */
    public static WechatTokenEntity getToken(String code) {
        WechatTokenEntity token = new WechatTokenEntity();
//        long now = new Date().getTime();
//        if (tokenTime != 0 && now - tokenTime < 7000000) {//token有效時(shí)間 7e6 毫秒
//            return token;
//        }
        String requestUrl = tokenUrl.replace("APPID", appid).replace("SECRET", appsecret).replace("CODE", code);
        // 發(fā)起GET請(qǐng)求獲取憑證
        JSONObject jsonObject = httpsRequest(requestUrl, "GET", null);
        if (null != jsonObject) {
            try {
                token.setUnionId(jsonObject.getString("unionid"));
                token.setOpenid(jsonObject.getString("openid"));
                token.setAccessToken(jsonObject.getString("access_token"));
                token.setRefreshToken(jsonObject.getString("refresh_token"));
                token.setExpiresIn(jsonObject.getInt("expires_in"));
            } catch (JSONException e) {
                token = null;
                // 獲取token失敗
                log.error("獲取token失敗 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));
            }
        }
        return token;
    }

    public static void main(String args[]) {
        // 獲取接口訪問憑證
//        我這里是直接從前端傳入accessToken,openid,所以可以直接拿到,下面是通過code生成
        String accessToken = getToken("code").getAccessToken();
        String openid = getToken("code").getOpenid();



//        /**
//         * 獲取用戶信息
//         */
        WechatUserEntity user = getUserInfo(accessToken, openid);
        //做這個(gè)測試的時(shí)候可以先關(guān)注,或者取消關(guān)注,控制臺(tái)會(huì)打印出來此用戶的openid
        System.out.println("OpenID:" + user.getOpenId());
        System.out.println("關(guān)注狀態(tài):" + user.getSubscribe());
        System.out.println("關(guān)注時(shí)間:" + user.getSubscribeTime());
        System.out.println("昵稱:" + user.getNickname());
        System.out.println("性別:" + user.getSex());
        System.out.println("國家:" + user.getCountry());
        System.out.println("省份:" + user.getProvince());
        System.out.println("城市:" + user.getCity());
        System.out.println("語言:" + user.getLanguage());
        System.out.println("頭像:" + user.getHeadImgUrl());
        getToken("02315v0w35TA603fsF0w3Q0fov415v0B");


    }

    /**
     * 獲取用戶信息
     *
     * @param accessToken 接口訪問憑證
     * @param openId      用戶標(biāo)識(shí)
     * @return WeixinUserInfo
     */
    public static WechatUserEntity getUserInfo(String accessToken, String openId) {

        WechatUserEntity wechatUserEntity = null;
        // 拼接請(qǐng)求地址
        String requestUrl = userInfoUrl.replace("ACCESS_TOKEN", accessToken).replace("OPENID", openId);
        // 獲取用戶信息
        JSONObject jsonObject = httpsRequest(requestUrl, "GET", null);
        if (null != jsonObject) {
            try {
                wechatUserEntity = new WechatUserEntity();
                // 用戶的標(biāo)識(shí)
                wechatUserEntity.setOpenId(jsonObject.getString("openid"));
                wechatUserEntity.setUnionId(jsonObject.getString("unionid"));
                // 關(guān)注狀態(tài)(1是關(guān)注,0是未關(guān)注),未關(guān)注時(shí)獲取不到其余信息
//                wechatUserEntity.setSubscribe(jsonObject.getInt("subscribe"));
                // 用戶關(guān)注時(shí)間
//                wechatUserEntity.setSubscribeTime(jsonObject.getString("subscribe_time"));
                // 昵稱
                wechatUserEntity.setNickname(jsonObject.getString("nickname"));
                // 用戶的性別(1是男性,2是女性,0是未知)
//                wechatUserEntity.setSex(jsonObject.getInt("sex"));
                // 用戶所在國家
//                wechatUserEntity.setCountry(jsonObject.getString("country"));
                // 用戶所在省份
//                wechatUserEntity.setProvince(jsonObject.getString("province"));
                // 用戶所在城市
//                wechatUserEntity.setCity(jsonObject.getString("city"));
                // 用戶的語言,簡體中文為zh_CN
                wechatUserEntity.setLanguage(jsonObject.getString("language"));
                // 用戶頭像
                wechatUserEntity.setHeadImgUrl(jsonObject.getString("headimgurl"));
            } catch (Exception e) {
                int errorCode = jsonObject.getInt("errcode");
                String errorMsg = jsonObject.getString("errmsg");
//                System.err.printf("獲取用戶信息失敗 errcode:{} errmsg:{}", errorCode, errorMsg);
            }
        }
        return wechatUserEntity;
    }

    /**
     * 發(fā)送https請(qǐng)求
     *
     * @param requestUrl    請(qǐng)求地址
     * @param requestMethod 請(qǐng)求方式(GET、POST)
     * @param outputStr     提交的數(shù)據(jù)
     * @return JSONObject(通過JSONObject.get ( key)的方式獲取json對(duì)象的屬性值)
     */
    public static JSONObject httpsRequest(String requestUrl, String requestMethod, String outputStr) {
        JSONObject jsonObject = null;
        try {
            // 創(chuàng)建SSLContext對(duì)象,并使用我們指定的信任管理器初始化
            TrustManager[] tm = {new WechatTrustManager()};
            SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
            sslContext.init(null, tm, new java.security.SecureRandom());
            // 從上述SSLContext對(duì)象中得到SSLSocketFactory對(duì)象
            SSLSocketFactory ssf = sslContext.getSocketFactory();

            URL url = new URL(requestUrl);
            HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
            conn.setSSLSocketFactory(ssf);

            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setUseCaches(false);
            // 設(shè)置請(qǐng)求方式(GET/POST)
            conn.setRequestMethod(requestMethod);

            // 當(dāng)outputStr不為null時(shí)向輸出流寫數(shù)據(jù)
            if (null != outputStr) {
                OutputStream outputStream = conn.getOutputStream();
                // 注意編碼格式
                outputStream.write(outputStr.getBytes(StandardCharsets.UTF_8));
                outputStream.close();
            }

            // 從輸入流讀取返回內(nèi)容
            InputStream inputStream = conn.getInputStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String str = null;
            StringBuilder stringBuilder = new StringBuilder();
            while ((str = bufferedReader.readLine()) != null) {
                stringBuilder.append(str);
            }

            // 釋放資源
            bufferedReader.close();
            inputStreamReader.close();
            inputStream.close();
            inputStream = null;
            conn.disconnect();
            jsonObject = JSONObject.fromObject(stringBuilder.toString());
        } catch (ConnectException ce) {
            System.err.printf("連接超時(shí):{}", ce);
        } catch (Exception e) {
            System.err.printf("https請(qǐng)求異常:{}", e);
        }
        return jsonObject;
    }
}


調(diào)用main方法就可以得到我們要的用戶信息了。

至于controller層怎么寫,大家可以參考一下我的

package com.jdzh.enterprise.wxlogin;

import com.jdzh.enterprise.framework.entity.RespBean;
import com.jdzh.enterprise.framework.entity.User;
import com.jdzh.enterprise.framework.service.IUserService;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.URL;
import java.nio.charset.StandardCharsets;


@RestController
@RequestMapping("/wx")
public class WxLoginController {
    @Autowired
    IUserService iUserService;
    private final static Logger log = LoggerFactory.getLogger(WechatUtils.class);
    private final static String appid = "appid "; //憑證
    private final static String appsecret = "appsecret "; //憑證密鑰

    // 憑證獲?。℅ET)
    public final static String tokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
    //userinfo
    public final static String userInfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";

    @GetMapping("/login")
    public RespBean login(String accessToken, String openid) {
//        System.out.println("code = " + code);
//        // 獲取接口訪問憑證
//        String accessToken = getToken(code).getAccessToken();
//        String openid = getToken(code).getOpenid();
        System.out.println("accessToken = " + accessToken);
        System.out.println("openid = " + openid);
        /**
         * 獲取用戶信息
         */
        WechatUserEntity wechatUserEntity = getUserInfo(accessToken, openid);
//        System.out.println("關(guān)注狀態(tài):" + wechatUserEntity.getSubscribe());
//        System.out.println("關(guān)注時(shí)間:" + wechatUserEntity.getSubscribeTime());
        System.out.println("昵稱:" + wechatUserEntity.getNickname());
//        System.out.println("性別:" + wechatUserEntity.getSex());
//        System.out.println("國家:" + wechatUserEntity.getCountry());
//        System.out.println("省份:" + wechatUserEntity.getProvince());
//        System.out.println("城市:" + wechatUserEntity.getCity());
//        System.out.println("語言:" + wechatUserEntity.getLanguage());
        System.out.println("頭像:" + wechatUserEntity.getHeadImgUrl());
        String nickname = wechatUserEntity.getNickname();
        if(wechatUserEntity!=null){
           //將用戶信息存在數(shù)據(jù)庫中
            User user = new User();
              user.setOpenid(openid);
              user.setNickname(nickname);
              user.setIsVip(0);
              //查詢openId是否存在
            User user1 = iUserService.findByOpenId(openid);
           if(user1==null){
               //如果不存在,則添加
               iUserService.save(user);
           }else{
               System.out.println("用戶信息已存在");
           }

           return RespBean.ok("登陸成功",wechatUserEntity);
       }else{
           return RespBean.error("登陸失敗",wechatUserEntity);
       }

    }

    /**
     * 獲取用戶信息
     *
     * @param accessToken 接口訪問憑證
     * @param openid      用戶標(biāo)識(shí)
     * @return WeixinUserInfo
     */
    public static WechatUserEntity getUserInfo(String accessToken, String openid) {

        WechatUserEntity wechatUserEntity = null;
        // 拼接請(qǐng)求地址
        String requestUrl = userInfoUrl.replace("ACCESS_TOKEN", accessToken).replace("OPENID", openid);
        // 獲取用戶信息
        JSONObject jsonObject = httpsRequest(requestUrl, "GET", null);
        if (null != jsonObject) {
            try {
                wechatUserEntity = new WechatUserEntity();
                // 用戶的標(biāo)識(shí)
                wechatUserEntity.setOpenId(jsonObject.getString("openid"));
                wechatUserEntity.setUnionId(jsonObject.getString("unionid"));
                // 關(guān)注狀態(tài)(1是關(guān)注,0是未關(guān)注),未關(guān)注時(shí)獲取不到其余信息
//                wechatUserEntity.setSubscribe(jsonObject.getInt("subscribe"));
                // 用戶關(guān)注時(shí)間
//                wechatUserEntity.setSubscribeTime(jsonObject.getString("subscribe_time"));
                // 昵稱
                wechatUserEntity.setNickname(jsonObject.getString("nickname"));
//                 用戶的性別(1是男性,2是女性,0是未知)
//                wechatUserEntity.setSex(jsonObject.getInt("sex"));
//                 用戶所在國家
//                wechatUserEntity.setCountry(jsonObject.getString("country"));
//                 用戶所在省份
//                wechatUserEntity.setProvince(jsonObject.getString("province"));
//                 用戶所在城市
//                wechatUserEntity.setCity(jsonObject.getString("city"));
                // 用戶的語言,簡體中文為zh_CN
//                wechatUserEntity.setLanguage(jsonObject.getString("language"));
                // 用戶頭像
                wechatUserEntity.setHeadImgUrl(jsonObject.getString("headimgurl"));
            } catch (Exception e) {
                int errorCode = jsonObject.getInt("errcode");
                String errorMsg = jsonObject.getString("errmsg");
                System.err.printf("獲取用戶信息失敗 errcode:{} errmsg:{}", errorCode, errorMsg);
            }
        }
        return wechatUserEntity;
    }

    /**
     * 發(fā)送https請(qǐng)求
     *
     * @param requestUrl    請(qǐng)求地址
     * @param requestMethod 請(qǐng)求方式(GET、POST)
     * @param outputStr     提交的數(shù)據(jù)
     * @return JSONObject(通過JSONObject.get ( key)的方式獲取json對(duì)象的屬性值)
     */
    public static JSONObject httpsRequest(String requestUrl, String requestMethod, String outputStr) {
        JSONObject jsonObject = null;
        try {
            // 創(chuàng)建SSLContext對(duì)象,并使用我們指定的信任管理器初始化
            TrustManager[] tm = {new WechatTrustManager()};
            SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
            sslContext.init(null, tm, new java.security.SecureRandom());
            // 從上述SSLContext對(duì)象中得到SSLSocketFactory對(duì)象
            SSLSocketFactory ssf = sslContext.getSocketFactory();

            URL url = new URL(requestUrl);
            HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
            conn.setSSLSocketFactory(ssf);

            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setUseCaches(false);
            // 設(shè)置請(qǐng)求方式(GET/POST)
            conn.setRequestMethod(requestMethod);

            // 當(dāng)outputStr不為null時(shí)向輸出流寫數(shù)據(jù)
            if (null != outputStr) {
                OutputStream outputStream = conn.getOutputStream();
                // 注意編碼格式
                outputStream.write(outputStr.getBytes(StandardCharsets.UTF_8));
                outputStream.close();
            }

            // 從輸入流讀取返回內(nèi)容
            InputStream inputStream = conn.getInputStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String str = null;
            StringBuilder stringBuilder = new StringBuilder();
            while ((str = bufferedReader.readLine()) != null) {
                stringBuilder.append(str);
            }

            // 釋放資源
            bufferedReader.close();
            inputStreamReader.close();
            inputStream.close();
            inputStream = null;
            conn.disconnect();
            jsonObject = JSONObject.fromObject(stringBuilder.toString());
        } catch (ConnectException ce) {
            System.err.printf("連接超時(shí):{}", ce);
        } catch (Exception e) {
            System.err.printf("https請(qǐng)求異常:{}", e);
        }
        return jsonObject;
    }
}

User類

package com.jdzh.enterprise.framework.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;


@TableName("user")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable , UserDetails {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 手機(jī)號(hào)
     */
    @TableField("phone")
    private String username;

    /**
     * 密碼
     */
    private String password;
    /**
     * openid
     */
    private  String openid;
    /**
     * 微信用戶名
     */
    private  String nickname;

    /**
     * 角色身份
     */
    @TableField("roleType")
    private Integer roleType;
    /**
     * 是否是vip
     */
    private Integer isVip;

    /**
     * vip截止日期
     */
    private String endTime;

    public Integer getIsVip() {
        return isVip;
    }

    public void setIsVip(Integer isVip) {
        this.isVip = isVip;
    }



    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }



    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return password;
    }




}

RespBean

package com.jdzh.enterprise.framework.entity;


public class RespBean {
    private Integer status;
    private String msg;
    private Object data;

    public static RespBean ok(String msg,Object data){
        return new RespBean(200,msg,data);
    }
    public static RespBean ok(String msg){
        return new RespBean(200,msg,null);
    }

    public static RespBean error(String msg,Object data){
        return new RespBean(500,msg,data);
    }
    public static RespBean error(String msg){
        return new RespBean(500,msg,null);
    }

    public RespBean() {
    }

    public RespBean(Integer status, String msg, Object data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}

數(shù)據(jù)庫設(shè)計(jì)

小伙伴們可以根據(jù)自己的需求設(shè)計(jì)數(shù)據(jù)庫表哦?

uni-app +java小程序端對(duì)接微信登陸文章來源地址http://www.zghlxwxcb.cn/news/detail-502363.html

到了這里,關(guān)于uni-app +java小程序端對(duì)接微信登陸的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • uni-app的優(yōu)缺點(diǎn);uniapp進(jìn)行條件編譯的兩種方法;小程序端和H5的代表值

    uni-app的優(yōu)缺點(diǎn);uniapp進(jìn)行條件編譯的兩種方法;小程序端和H5的代表值

    目錄 uni-app的優(yōu)缺點(diǎn) 優(yōu)點(diǎn): 1.跨平臺(tái)開發(fā): 2.統(tǒng)一的開發(fā)語言: 3.高效的性能: 4.豐富的生態(tài)圈: 缺點(diǎn): 1.平臺(tái)差異性: 2.性能限制: 3.對(duì)新特性支持滯后: Uni-app條件編譯 process.env.UNI_PLATFORM 變量: 使用 process.env.NODE_ENV 變量: Uni-app中的代表值 Uni-app 是一個(gè)跨平臺(tái)的開發(fā)框架

    2024年02月08日
    瀏覽(570)
  • uni-app啟動(dòng)小程序篇(字節(jié),微信)

    uni-app啟動(dòng)小程序篇(字節(jié),微信)

    uni-app啟動(dòng)小程序篇 uni-app在字節(jié)工具小程序啟動(dòng) 1.1 在Hbuild X點(diǎn)擊運(yùn)行, 進(jìn)入運(yùn)行設(shè)置 1.2 進(jìn)入運(yùn)行設(shè)置后,設(shè)置字節(jié)小程序的運(yùn)行位置 ? 1.3 以上配置完成后,點(diǎn)擊運(yùn)行到小程序 ? 1.4 啟動(dòng)成功后 復(fù)制該地址 ? 1.5 打開字節(jié)小程序,選小程序,點(diǎn)擊新建 ? 1.6 進(jìn)入后點(diǎn)擊導(dǎo)入項(xiàng)目,將剛

    2024年02月11日
    瀏覽(24)
  • 1個(gè)月uni-app微信小程序開發(fā)上線實(shí)戰(zhàn)專欄介紹

    1個(gè)月uni-app微信小程序開發(fā)上線實(shí)戰(zhàn)專欄介紹

    《uni-app開發(fā)微信小程序1個(gè)月上線實(shí)戰(zhàn)》,目標(biāo)帶領(lǐng)1000位同學(xué)成功開發(fā)上線一個(gè)自己的個(gè)人小程序! 作者介紹 :國服第二切圖仔——資深前端開發(fā)工程師,具有六年以上的前端開發(fā)經(jīng)驗(yàn),曾在多家知名企業(yè)任職,CSDN、阿里云、華為云等平臺(tái)優(yōu)質(zhì)創(chuàng)作者,擅長前端性能優(yōu)化,

    2023年04月16日
    瀏覽(30)
  • 微信小程序開發(fā)學(xué)習(xí)筆記《17》uni-app框架-tabBar

    微信小程序開發(fā)學(xué)習(xí)筆記《17》uni-app框架-tabBar

    博主正在學(xué)習(xí)微信小程序開發(fā),希望記錄自己學(xué)習(xí)過程同時(shí)與廣大網(wǎng)友共同學(xué)習(xí)討論。建議仔細(xì)閱讀uni-app對(duì)應(yīng)官方文檔 運(yùn)行如下的命令,基于master分支在本地創(chuàng)建tabBar子分支,用來開發(fā)和tabBar相關(guān)的功能: 在 pages目錄中,創(chuàng)建首頁(home)、分類(cate)、購物車(cart)、我的(my)這4個(gè)

    2024年02月20日
    瀏覽(24)
  • 【uni-app】微信小程序開發(fā) node_modules 模塊丟失問題

    【uni-app】微信小程序開發(fā) node_modules 模塊丟失問題

    ?解決問題 重要的問題說三遍?。。?解決 HBuilderX 打包 uni-app 項(xiàng)目到微信小程序時(shí),node_modules 文件夾丟失問題。 解決 HBuilderX 打包 uni-app 項(xiàng)目到微信小程序時(shí),node_modules 文件夾丟失問題。 解決 HBuilderX 打包 uni-app 項(xiàng)目到微信小程序時(shí),node_modules 文件夾丟失問題。 一、uni-a

    2024年02月11日
    瀏覽(24)
  • uni-app+vue3+vite+微信小程序開發(fā)的問題點(diǎn)

    目錄名稱不能為api,否則會(huì)出現(xiàn) ├F10: PM┤ [vite] getaddrinfo ENOTFOUND rivtrust.jz-xxx.xyz ,修改為_api; vue3的全局變量掛載 或者 全局變量的引入: 或者 axios在微信小程序上使用的問題: 安裝模塊 出現(xiàn)adapter is not a function的解決方法 需要axios自定義適配器配置 整體代碼request.js: un

    2024年02月13日
    瀏覽(48)
  • uni-app微信小程序開發(fā)自定義select下拉多選內(nèi)容篇

    uni-app微信小程序開發(fā)自定義select下拉多選內(nèi)容篇

    歡迎點(diǎn)擊領(lǐng)取 -《前端開發(fā)面試題進(jìn)階秘籍》:前端登頂之巔-最全面的前端知識(shí)點(diǎn)梳理總結(jié) 技術(shù)框架公司的選型:uni-app + uni-ui + vue3 + vite4 + ts 需求分析:微信小程序-uni-ui內(nèi)容 1、創(chuàng)建一個(gè)自定義的下拉,支持多個(gè)內(nèi)容的同時(shí)多選 2、定義好出入?yún)?shù),支持回顯內(nèi)容等 3、綁定

    2024年02月13日
    瀏覽(20)
  • Uni-App 中使用微信小程序開發(fā),你可以通過以下步驟來設(shè)置節(jié)點(diǎn)屬性

    在 Uni-App 中使用微信小程序開發(fā),你可以通過以下步驟來設(shè)置節(jié)點(diǎn)屬性: 在模板中定義節(jié)點(diǎn):在 wxml 文件中,使用標(biāo)簽定義要操作的節(jié)點(diǎn),并為它添加一個(gè)唯一的 id 屬性,例如: ? 在 js 文件中獲取節(jié)點(diǎn)的引用:使用? uni.createSelectorQuery() ?方法創(chuàng)建選擇器查詢對(duì)象,并使用

    2024年02月15日
    瀏覽(22)
  • 即時(shí)通訊實(shí)現(xiàn)微信掃碼登錄web網(wǎng)站(vue + uni-app + java + 微信小程序)
  • uni-app移動(dòng)端-H5-微信小程序下載保存圖片,文檔和視頻到手機(jī),帶進(jìn)度條

    可移步插件地址,可直接導(dǎo)入hbuilderx示例項(xiàng)目查看: uni-app移動(dòng)端-H5-微信小程序下載保存圖片,文檔和視頻到手機(jī),帶進(jìn)度條 具體代碼如下

    2024年02月13日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包