func resourceBuildToDir(ImportPackageList []string, tmpDirPath string) (response resourceBuildToDirResponse) { builder := &tBuilder{ pkgMap: map[string]*pkg{}, } for _, importPath := range ImportPackageList { builder.handlePkg(importPath) } for _, pkg := range builder.pkgDepOrder { builder.JsContent = append(builder.JsContent, pkg.JsContent...) builder.JsContent = append(builder.JsContent, byte('\n')) builder.CssContent = append(builder.CssContent, pkg.CssContent...) builder.CssContent = append(builder.CssContent, byte('\n')) } response.CssFileName = kmgCrypto.Md5Hex(builder.CssContent) + ".css" response.JsFileName = kmgCrypto.Md5Hex(builder.JsContent) + ".js" kmgFile.MustMkdir(tmpDirPath) kmgFile.MustWriteFile(filepath.Join(tmpDirPath, response.CssFileName), builder.CssContent) kmgFile.MustWriteFile(filepath.Join(tmpDirPath, response.JsFileName), builder.JsContent) for _, pkg := range builder.pkgDepOrder { for _, filePath := range pkg.ResourceFilePathList { kmgFile.MustWriteFile(filepath.Join(tmpDirPath, filepath.Base(filePath)), kmgFile.MustReadFile(filePath)) } } for _, pkg := range builder.pkgDepOrder { response.NeedCachePathList = append(response.NeedCachePathList, pkg.Dirpath) } response.ImportPackageList = ImportPackageList return response }
//这个函数使用md5方式对query添加签名,没有数据的参数会被删除,并且直接更新输入的query数组. // 和手机app版细节有所不同. func (ot *OverseaTrade) md5Sign(query map[string]string) { kvList := make([]kv, 0, len(query)) for k, v := range query { if v == "" { delete(query, k) continue } kvList = append(kvList, kv{ K: k, V: v, }) } sort.Sort(kvSorter(kvList)) toEncodeList := make([]string, len(kvList)) for i, data := range kvList { toEncodeList[i] = data.K + `=` + data.V } toSign := strings.Join(toEncodeList, "&") //fmt.Println(kmgBase64.Base64EncodeStringToString(toSign)) signed := kmgCrypto.Md5Hex([]byte(toSign + ot.SecurityCode)) query["sign_type"] = "MD5" query["sign"] = signed return }
// 如果没有数据会返回nil func MustKvdbGetBytes(s string) (b []byte) { key := kmgCrypto.Md5Hex([]byte(s)) content, err := kmgFile.ReadFile(kmgConfig.DefaultEnv().PathInTmp("kvdb/" + key)) if err != nil { if os.IsNotExist(err) { return nil } panic(err) } return content }
func MustKvdbSetBytes(s string, b []byte) { key := kmgCrypto.Md5Hex([]byte(s)) kmgFile.MustWriteFileWithMkdir(kmgConfig.DefaultEnv().PathInTmp("kvdb/"+key), b) }