WeChat applet development – left and right linkage of menu content & MD5 encryption

Hits: 0

<view class=”box” id=”{{item.viewId}}” wx:for=”{{allGoods}}” wx:key=”unique” wx:for-index=”typeId”>

js file modification:
add in page data:


Then modify the following function:
selectMenuAct: function (e) {

var id = e.target.dataset.id;
var tType=this.data.menuType[id];
  scrollNum: id,
  toView: tType
  //scrollTop: this.data.heightList[id]

passed in the test environment.

The scroll-into-view value should be a child element id (id cannot start with a number). Sets which direction to scroll to the element in which direction.

2. WeChat applet MD5 encryption

In general, many languages ​​have MD5 encryption libraries.

If you are referring to data encryption, I am afraid that the plaintext of the data is not safe. I suggest to use base64 + some prefixes or suffixes for encryption, and then transmit the data to the server, and the server decrypts and removes these suffixes and suffixes. For example, the plaintext is abc, you can add a prefix to it 123abc, then encrypt it MTIzYWJjand send it out, and then decrypt it again.

General MD5 encryption is irreversible. And base64 can be encoded and decoded as follows:

package main

import ( "fmt" "github.com/hunterhug/GoSpider/util" )

func main() { s := "abc" prefix := "123" base64e := util.Base64E(prefix + s) fmt.Println( "Encryption:" + base64e) fmt.Println( "Decrypt again: " + util.Base64D(base64e)) }


Encryption: MTIzYWJj
Re-decryption: 123abc

Baidu Encyclopedia: Base64 encoding can be used to transmit long identification information in the HTTP environment. For example, in the Java Persistence system Hibernate, Base64 is used to encode a long unique identifier (usually a 128-bit UUID) into a string, which is used as a parameter in HTTP forms and HTTP GET URLs. In other applications, it is often necessary to encode binary data in a form suitable for placement in URLs (including hidden form fields). At this time, the use of Base64 encoding is not only short, but also unreadable, that is, the encoded data will not be directly seen by the naked eye.

The encryption library packaged by my Golang language is generally like this:

Copyright 2017 by GoSpider author.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.

package util

import ( "crypto/hmac" "crypto/md5" "crypto/sha256" "encoding/base64" "encoding/hex" "fmt" "net/url" "strings" )

func ComputeHmac256(message string, secret string) string { key := []byte(secret) h := hmac.New(sha256.New, key) h.Write([]byte(message)) return base64.StdEncoding.EncodeToString(h.Sum(nil)) }

// create md5 string func Strtomd5(s string) string { h := md5.New() h.Write([]byte(s)) rs := hex.EncodeToString(h.Sum(nil)) return rs }

func Md5(str string) string { return Strtomd5(str) }

// String base64 encryption func Base64E ( urlstring string ) string { str := []byte(urlstring) data := base64.StdEncoding.EncodeToString(str) return data }

// String base64 decrypt func Base64D ( urlxxstring string ) string { data, err := base64.StdEncoding.DecodeString(urlxxstring) if err != nil { return "" } s := fmt.Sprintf("%q", data) s = strings.Replace(s, "\"", "", -1) return s }

func UrlE(s string) string { return url.QueryEscape(s) }

func UrlD(s string) string { s, e := url.QueryUnescape(s) if e != nil { return e.Error() } else { return s } }

Most sites now enable https to ensure data security.

Reprinted in: https://my.oschina.net/u/3396785/blog/1512505

You may also like...

Leave a Reply

Your email address will not be published.