diff --git a/example/app/AES.go b/example/app/AES.go new file mode 100644 index 0000000..72b8510 --- /dev/null +++ b/example/app/AES.go @@ -0,0 +1,106 @@ +package app + +import ( + "bytes" + "crypto/aes" + "crypto/cipher" + "encoding/base64" + "errors" +) + +//高级加密标准(Adevanced Encryption Standard ,AES) + +//16,24,32位字符串的话,分别对应AES-128,AES-192,AES-256 加密方法 +//key不能泄露 +var PwdKey = []byte("mif022h3g9geAHUHY432,:da1adag389") + +//PKCS7 填充模式 +func pKCS7Padding(ciphertext []byte, blockSize int) []byte { + padding := blockSize - len(ciphertext)%blockSize + //Repeat()函数的功能是把切片[]byte{byte(padding)}复制padding个,然后合并成新的字节切片返回 + padtext := bytes.Repeat([]byte{byte(padding)}, padding) + return append(ciphertext, padtext...) +} + +//填充的反向操作,删除填充字符串 +func pKCS7UnPadding(origData []byte) ([]byte, error) { + //获取数据长度 + length := len(origData) + if length == 0 { + return nil, errors.New("加密字符串错误!") + } else { + //获取填充字符串长度 + unpadding := int(origData[length-1]) + //截取切片,删除填充字节,并且返回明文 + return origData[:(length - unpadding)], nil + } +} + +//实现加密 +func AesEcrypt(origData []byte, key []byte) ([]byte, error) { + //创建加密算法实例 + block, err := aes.NewCipher(key) + if err != nil { + return nil, err + } + //获取块的大小 + blockSize := block.BlockSize() + //对数据进行填充,让数据长度满足需求 + origData = pKCS7Padding(origData, blockSize) + //采用AES加密方法中CBC加密模式 + blocMode := cipher.NewCBCEncrypter(block, key[:blockSize]) + crypted := make([]byte, len(origData)) + //执行加密 + blocMode.CryptBlocks(crypted, origData) + return crypted, nil +} + +//实现解密 +func AesDeCrypt(cypted []byte, key []byte) ([]byte, error) { + //创建加密算法实例 + block, err := aes.NewCipher(key) + if err != nil { + return nil, err + } + //获取块大小 + blockSize := block.BlockSize() + //创建加密客户端实例 + blockMode := cipher.NewCBCDecrypter(block, key[:blockSize]) + origData := make([]byte, len(cypted)) + //这个函数也可以用来解密 + blockMode.CryptBlocks(origData, cypted) + //去除填充字符串 + origData, err = pKCS7UnPadding(origData) + if err != nil { + return nil, err + } + return origData, err +} + +//加密base64 +func EnPwdCode(pwd []byte) (string, error) { + result, err := AesEcrypt(pwd, PwdKey) + if err != nil { + return "", err + } + return base64.StdEncoding.EncodeToString(result), err +} + +//解密 +func DePwdCode(pwd string) ([]byte, error) { + //解密base64字符串 + pwdByte, err := base64.StdEncoding.DecodeString(pwd) + if err != nil { + return nil, err + } + //执行AES解密 + return AesDeCrypt(pwdByte, PwdKey) + +} + +//func main() { +// str := []byte("12fff我是ww.topgoer.com的站长枯藤") +// pwd, _ := EnPwdCode(str) +// bytes, _ := DePwdCode(pwd) +// fmt.Println(string(bytes)) +//} diff --git a/example/app/declare.go b/example/app/declare.go index 5730008..d151ee5 100644 --- a/example/app/declare.go +++ b/example/app/declare.go @@ -388,15 +388,15 @@ var DeclareCtr = Ctr{ res = append(res, article) } - minMoney := 0 - maxMoney := 0 + minMoney := float64(0) + maxMoney := float64(0) for _, v := range res { if v.GetMap("declare") != nil { - if v.GetMap("declare").GetInt("money_scope_min") < minMoney { - minMoney = v.GetMap("declare").GetInt("money_scope_min") + if v.GetMap("declare").GetFloat64("money_scope_min") < minMoney { + minMoney = v.GetMap("declare").GetFloat64("money_scope_min") } - if v.GetMap("declare").GetInt("money_scope_max") > maxMoney { - maxMoney = v.GetMap("declare").GetInt("money_scope_max") + if v.GetMap("declare").GetFloat64("money_scope_max") > maxMoney { + maxMoney = v.GetMap("declare").GetFloat64("money_scope_max") } } } @@ -410,11 +410,11 @@ var DeclareCtr = Ctr{ "del_flag": 0, } if maxMoney != minMoney { - seData["money_scope"] = ObjToStr(minMoney) + "-" + ObjToStr(maxMoney) + "万元" + seData["money_scope"] = ObjToStr(ObjToInt(minMoney)) + "-" + ObjToStr(ObjToInt(maxMoney)) + "" } else if maxMoney == 0 { seData["money_scope"] = "" } else { - seData["money_scope"] = ObjToStr(maxMoney) + "万元" + seData["money_scope"] = ObjToStr(ObjToInt(maxMoney)) + "" } //匹配记录存储 diff --git a/example/app/init.go b/example/app/init.go index 3f996be..19c5f70 100644 --- a/example/app/init.go +++ b/example/app/init.go @@ -5,6 +5,7 @@ import ( . "code.hoteas.com/golang/hotime/common" "errors" "time" + "unicode/utf8" ) // Project 管理端项目 @@ -22,6 +23,7 @@ var Project = Proj{ "search_record": SearchRecordCtr, "sms": Sms, "tag": TagCtr, + "upan": UpanCtr, "user": UserCtr, "vip_order": VipOrderCtr, "websocket": WebsocketCtr, @@ -109,3 +111,15 @@ func auth(that *Context, phone, companyName string) error { return nil } + +// FilterEmoji 过滤 emoji 表情 +func FilterEmoji(content string) string { + new_content := "" + for _, value := range content { + _, size := utf8.DecodeRuneInString(string(value)) + if size <= 3 { + new_content += string(value) + } + } + return new_content +} diff --git a/example/app/upan.go b/example/app/upan.go new file mode 100644 index 0000000..182340e --- /dev/null +++ b/example/app/upan.go @@ -0,0 +1,84 @@ +package app + +import ( + . "code.hoteas.com/golang/hotime" + "code.hoteas.com/golang/hotime/common" + "fmt" + "strings" +) + +var UpanCtr = Ctr{ + "login": func(that *Context) { + timestamp := that.Req.FormValue("timestamp") + sn := that.Req.FormValue("sn") + + //str,_:=EnPwdCode([]byte(lus[len(lus)-1]+":"+ObjToStr(t)))// + re, e := DePwdCode(sn) + + if e != nil { + that.Display(3, "数据异常") + return + } + reStr := string(re) + realSn := strings.Replace(reStr, ":"+timestamp, "", -1) + if len(realSn)+len(timestamp)+1 != len(reStr) { + that.Display(4, "数据验证失败") + return + } + fmt.Println("U盘校验", realSn) + user := that.Db.Get("user", "*", common.Map{"upankey": realSn}) + if user == nil { + that.Display(5, "还没有绑定用户") + return + } + + that.Session("user_id", user.GetCeilInt("id")) + that.Display(0, "登录成功") + }, + + "create": func(that *Context) { + timestamp := that.Req.FormValue("timestamp") + sn := that.Req.FormValue("sn") + + //str,_:=EnPwdCode([]byte(lus[len(lus)-1]+":"+ObjToStr(t)))// + re, e := DePwdCode(sn) + + if e != nil { + that.Display(3, "数据异常") + return + } + reStr := string(re) + realSn := strings.Replace(reStr, ":"+timestamp, "", -1) + if len(realSn)+len(timestamp)+1 != len(reStr) { + that.Display(4, "数据验证失败") + return + } + + fmt.Println("U盘校验", realSn) + + uuser := that.Db.Get("user", "id", common.Map{"upankey": realSn}) + + if uuser != nil { + that.Display(4, "已经绑定了其他企业") + return + } + + phone := that.Req.FormValue("phone") + companyName := that.Req.FormValue("company_name") + //验证不成功则反馈 + err := auth(that, phone, companyName) + if err != nil { + fmt.Println(err) + that.Display(3, err.Error()) + return + } + + num := that.Db.Update("user", common.Map{"upankey": realSn}, common.Map{"id": that.Session("user_id").Data}) + if num == 0 { + that.Display(4, "更新失败") + return + } + that.Display(0, "绑定成功") + + }, +} diff --git a/example/app/vip_order.go b/example/app/vip_order.go index 9eed5d7..17ee5aa 100644 --- a/example/app/vip_order.go +++ b/example/app/vip_order.go @@ -46,7 +46,7 @@ var VipOrderCtr = Ctr{ data := Map{ "sn": "SN" + time.Now().Format("20060102150405") + getSn(), //"name":"1年VIP会员", - "amount": 72000, //720元 + "amount": 36000, //720元 "user_id": user.GetCeilInt64("id"), "company_id": user.GetCeilInt("company_id"), "expiration_time": time.Now().Add(365 * 24 * time.Hour).Format("2006-01-02 15:04:05"), @@ -73,7 +73,7 @@ var VipOrderCtr = Ctr{ data["amount"] = 36000 //tp=tp } - data["amount"] = 1 + //data["amount"] = 1 if user.GetCeilInt("salesman_id") != 0 { data["salesman_id"] = user.GetCeilInt("salesman_id") diff --git a/example/app/wechath5.go b/example/app/wechath5.go index 9afaab7..2e2fa08 100644 --- a/example/app/wechath5.go +++ b/example/app/wechath5.go @@ -29,7 +29,7 @@ var Wechath5 = Ctr{ "retoken": resToken.RefreshToken, "appid": appid, "unionid": userInfo.Unionid, - "nickname": userInfo.Nickname, + "nickname": FilterEmoji(userInfo.Nickname), "avatar": userInfo.HeadImgURL, "create_time[#]": "now()", "modify_time[#]": "now()", diff --git a/example/provider/init.go b/example/provider/init.go index c859752..d735eae 100644 --- a/example/provider/init.go +++ b/example/provider/init.go @@ -4,6 +4,7 @@ import ( . "code.hoteas.com/golang/hotime" . "code.hoteas.com/golang/hotime/common" "time" + "unicode/utf8" ) // Project 管理端项目 @@ -33,3 +34,15 @@ func getCode() string { //} return res } + +// 过滤 emoji 表情 +func FilterEmoji(content string) string { + new_content := "" + for _, value := range content { + _, size := utf8.DecodeRuneInString(string(value)) + if size <= 3 { + new_content += string(value) + } + } + return new_content +} diff --git a/example/provider/salesman.go b/example/provider/salesman.go index e325acc..b0f41fd 100644 --- a/example/provider/salesman.go +++ b/example/provider/salesman.go @@ -22,6 +22,15 @@ var Salesman = Ctr{ that.Display(4, "找不到该业务员") return } + + if salesman.GetString("nickname") == "" { + wechat := that.Db.Get("wechat", "*", Map{"salesman_id": salesman.GetCeilInt64("id")}) + if wechat != nil { + salesman["nickname"] = wechat.GetString("nickname") + salesman["avatar"] = wechat.GetString("avatar") + that.Db.Update("salesman", Map{"nickname": wechat.GetString("nickname"), "avatar": wechat.GetString("avatar")}, Map{"id": salesman.GetCeilInt64("id")}) + } + } salesman["user"] = that.Db.Count("user", Map{"AND": Map{"salesman_id": that.Session("salesman_id").Data, "del_flag": 0}}) salesman["matters"] = that.Db.Count("matters", Map{"AND": Map{"salesman_id": that.Session("salesman_id").Data, "del_flag": 0}}) diff --git a/example/provider/wechat.go b/example/provider/wechat.go index 21c5638..2d1b9ee 100644 --- a/example/provider/wechat.go +++ b/example/provider/wechat.go @@ -29,7 +29,7 @@ var Wechat = Ctr{ "retoken": resToken.RefreshToken, "appid": appid, "unionid": userInfo.Unionid, - "nickname": userInfo.Nickname, + "nickname": FilterEmoji(userInfo.Nickname), "avatar": userInfo.HeadImgURL, //"create_time[#]":"now()", "modify_time[#]": "now()", diff --git a/example/tpt/pc.html b/example/tpt/pc.html new file mode 100644 index 0000000..e4cd5a2 --- /dev/null +++ b/example/tpt/pc.html @@ -0,0 +1,32 @@ + + + + + 微信登录 + + + + + +