增加天府通办登录
This commit is contained in:
@@ -4,11 +4,17 @@ import (
|
||||
. "../../../hotime"
|
||||
. "../../../hotime/common"
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/sha256"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -82,3 +88,34 @@ func tencentSendYzm(umobile, code string) error {
|
||||
fmt.Println("response Body:", string(body))
|
||||
return nil
|
||||
}
|
||||
|
||||
var privateKey = `-----BEGIN RSA Private Key-----
|
||||
MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAJJuFUH/4m9H5hCCzxtd9BxpjWlG9gbejqiJpV0XJKaU1V7xDBJasswxPY7Zc15RoxWClPoKPwKrbWKm49dgBJebJq5xd4sLCSbboxRkKxpRiJHMZ4LJjYa5h9Ei9RyfoUzqGHqH4UrDy3m3IwPiP19cIBqoU50shyQf92ZpcGZhAgMBAAECgYEAiadU8pODoUs82x6tZbPALQmJN4PO+wwznfqv6sA74yGdKECAMazz0oMjtGt1SiCCqFD2jcweCftvvELZg3mvNg1V0vRQRD1ZCA8HDp8DXm20d11K3+RX39tR4KgyyM3HsSEhkUDujMxKIpYjyiB5iEtV7Ja9bZ2fROszq+mUIqUCQQDQQf6vWRMLBqfnDcU77vuDGOhXbjkF2ytLxLW3fbKaW3GWvC3n93zPM+mcvWSXgkl448+jFjpMktm1Vn+w+YX3AkEAs/+bbRbod6AcVbLu8C5E44qDRoRpu+LF7Cphp8tlSAIRjm2yGP5acMWGRUtH9MF2QJYPF0PgDzdmUSVqWnCAZwJBALnSuRri4wAKn1SmT+ALfLZcSiyBODZGeppv2ijw6qWahH8YR+ncRaxoyMFHqPMbmM1akJIXqktbGREaLnPOIb8CQQCdJycJaL3Qa98xR4dr9cm5rF6PO96g5w6M8jfO6ztjUkMHymh7f99wpFRlvaN2Y06edyV315ARWPohEPy5N44zAkBlLuDHLm1TkTTAfdlL5r2OcdjpaJYloTdn05Mp3+J+w1zTX8k6Mz8lFZtLUcoMeTfQ9rm/+u2KwxS8NljtSZWH
|
||||
-----END RSA Private Key-----
|
||||
`
|
||||
|
||||
func RSA_Decrypt(cipherTextBase64 string) string {
|
||||
cipherText, _ := base64.StdEncoding.DecodeString(cipherTextBase64)
|
||||
buf := []byte(privateKey)
|
||||
//pem解码
|
||||
block, _ := pem.Decode(buf)
|
||||
//X509解码
|
||||
private, err := x509.ParsePKCS8PrivateKey(block.Bytes)
|
||||
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
//对密文进行解密
|
||||
//plainText,_:=rsa.DecryptPKCS1v15(rand.Reader,privateKey,cipherText)
|
||||
|
||||
v, err := rsa.DecryptPKCS1v15(rand.Reader, private.(*rsa.PrivateKey), cipherText)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
//返回明文
|
||||
v1, err1 := url.QueryUnescape(string(v))
|
||||
if err1 != nil {
|
||||
return ""
|
||||
}
|
||||
return v1
|
||||
}
|
||||
|
||||
@@ -13,6 +13,45 @@ var userCtr = Ctr{
|
||||
"test": func(this *Context) {
|
||||
this.Session("id", 1)
|
||||
},
|
||||
//自带的登录
|
||||
"login": func(this *Context) {
|
||||
|
||||
phone := RSA_Decrypt(this.Req.FormValue("phone"))
|
||||
idcard := RSA_Decrypt(this.Req.FormValue("idcard"))
|
||||
name := RSA_Decrypt(this.Req.FormValue("name"))
|
||||
|
||||
if len(phone) != 11 ||
|
||||
len(idcard) != 18 ||
|
||||
len(name) < 1 {
|
||||
this.Display(3, "数据校验不通过")
|
||||
}
|
||||
|
||||
user := this.Db.Get("user", "*", Map{"phone": phone})
|
||||
|
||||
if user == nil {
|
||||
user = Map{"phone": phone, "idcard": idcard, "name": name, "create_time": time.Now().Unix(), "modify_time": time.Now().Unix()}
|
||||
user["id"] = this.Db.Insert("user", user)
|
||||
|
||||
} else {
|
||||
user["phone"] = phone
|
||||
user["idcard"] = idcard
|
||||
user["name"] = name
|
||||
user["modify_time"] = time.Now().Unix()
|
||||
re := this.Db.Update("user", user, Map{"id": user.GetCeilInt64("id")})
|
||||
if re == 0 {
|
||||
this.Display(4, "系统错误")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if user.GetCeilInt64("id") == 0 {
|
||||
this.Display(5, "登录失败")
|
||||
return
|
||||
}
|
||||
this.Session("id", user.GetCeilInt("id"))
|
||||
this.Display(0, "登录成功")
|
||||
|
||||
},
|
||||
"add": func(this *Context) {
|
||||
if this.Req.FormValue("code") != this.Session("code").ToStr() ||
|
||||
this.Req.FormValue("phone") != this.Session("phone").ToStr() {
|
||||
@@ -48,6 +87,7 @@ var userCtr = Ctr{
|
||||
}
|
||||
|
||||
this.Session("id", user.GetCeilInt("id"))
|
||||
this.Session("code", nil)
|
||||
this.Display(0, "登录成功")
|
||||
|
||||
},
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user