|
@@ -0,0 +1,57 @@
|
|
|
+package service
|
|
|
+
|
|
|
+import (
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ IC "bp.jydev.jianyu360.cn/BaseService/biCenter/api/common"
|
|
|
+ "crypto/rand"
|
|
|
+ "crypto/rsa"
|
|
|
+ "crypto/x509"
|
|
|
+ "encoding/base64"
|
|
|
+ "encoding/pem"
|
|
|
+ "net/url"
|
|
|
+)
|
|
|
+
|
|
|
+type InfoService struct {
|
|
|
+}
|
|
|
+
|
|
|
+func (l *InfoService) Myinfo(sid string) map[string]interface{} {
|
|
|
+ infoMap := map[string]interface{}{}
|
|
|
+ info_i := redis.Get("session", sid)
|
|
|
+ if info_i != nil {
|
|
|
+ info_m, _ := info_i.(map[string]interface{})
|
|
|
+ infoMap = map[string]interface{}{
|
|
|
+ "nickName": RsaEncrypt([]byte(common.InterfaceToStr(info_m["s_nickname"]))),
|
|
|
+ "entRole": RsaEncrypt([]byte(common.InterfaceToStr(info_m["entRole"]))),
|
|
|
+ "entNicheDis": RsaEncrypt([]byte(common.InterfaceToStr(info_m["entNicheDis"]))),
|
|
|
+ "positionId": RsaEncrypt([]byte(common.InterfaceToStr(info_m["positionId"]))),
|
|
|
+ "accountId": RsaEncrypt([]byte(common.InterfaceToStr(info_m["s_nickname"]))),
|
|
|
+ "entAccountId": RsaEncrypt([]byte(common.InterfaceToStr(info_m["s_nickname"]))),
|
|
|
+ "entId": RsaEncrypt([]byte(common.InterfaceToStr(info_m["entId"]))),
|
|
|
+ "entName": RsaEncrypt([]byte(common.InterfaceToStr(info_m["entName"]))),
|
|
|
+ "entUserName": RsaEncrypt([]byte(common.InterfaceToStr(info_m["entUserName"]))),
|
|
|
+ "entUserId": RsaEncrypt([]byte(common.InterfaceToStr(info_m["entUserId"]))),
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return infoMap
|
|
|
+}
|
|
|
+
|
|
|
+// 加密
|
|
|
+func RsaEncrypt(origData []byte) string {
|
|
|
+ //解密pem格式的公钥
|
|
|
+ block, _ := pem.Decode([]byte(IC.C.PublicKey))
|
|
|
+ if block == nil {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ // 解析公钥
|
|
|
+ pubInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
|
|
|
+ if err != nil {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ // 类型断言
|
|
|
+ pub := pubInterface.(*rsa.PublicKey)
|
|
|
+ //加密
|
|
|
+ data, _ := rsa.EncryptPKCS1v15(rand.Reader, pub, origData)
|
|
|
+ v1 := url.QueryEscape(base64.StdEncoding.EncodeToString(data))
|
|
|
+ return v1
|
|
|
+}
|