| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package main
- import (
- "fmt"
- "mtp2_if/utils"
- "reflect"
- "sort"
- "github.com/fatih/structs"
- )
- type aPIAAA struct {
- Account string `json:"account" binding:"required"` // 用户唯一识别码(请转入UserID)
- SerialNo string `json:"serialNo"` // 实名认证流水号
- Name *string `json:"name" structs:",omitempty"` // 用户姓名
- IdCard string `json:"idCard" structs:",omitempty"` // 个人身份证、台胞证、港澳通行证等证件号
- IdCardType *int `json:"idCardType" structs:",omitempty"` // 证件类型 1:居民身份证 2:台湾居民来往内地通行证 3:港澳居民往来内地通行证 10:武装警察身份证 11:军人身份证 15:警察(警官)证 21:外国人永久居留证 23:护照
- Mobile string `json:"mobile" structs:",omitempty"` // 手机号码
- SignPwd string `json:"signPwd" structs:",omitempty"` // 签约密码(MTP2登录密码加密方式),如果为空将随机生成签约密码(当签约方式为“签约密码签约”时会使用到,可通过重置接口修改)
- IsSignPwdNotice *float64 `json:"isSignPwdNotice" structs:",omitempty"` // 是否将签约密码以短信形式通知用户 0:不通知(默认) 1:通知
- IsNotice *bool `json:"isNotice" structs:",omitempty"` // 用户发起合同或需要签署时是否进行短信通知 0:否(默认) 1:是
- }
- func main() {
- req := &aPIAAA{
- Account: "1111",
- }
- req.SerialNo = "2222"
- req.Name = utils.SetPointValue("")
- req.IdCardType = utils.SetPointValue(1)
- req.IsSignPwdNotice = utils.SetPointValue(5.01)
- reqMap := structs.Map(req)
- aaa := sortMapByKey(reqMap)
- fmt.Println(aaa)
- }
- func sortMapByKey(data map[string]interface{}) (sortedData string) {
- keys := make([]string, 0, len(data))
- for k := range data {
- keys = append(keys, k)
- }
- sort.Strings(keys)
- for i, k := range keys {
- if i > 0 {
- sortedData += ","
- }
- // 判断是否指针
- v := reflect.ValueOf(data[k])
- if v.Kind() == reflect.Ptr {
- switch data[k].(type) {
- case *string:
- sortedData += fmt.Sprintf(`"%s":"%s"`, k, *(data[k].(*string)))
- case *map[string]interface{}:
- sortedData += fmt.Sprintf(`"%s":%s`, k, sortMapByKey(*(data[k].(*map[string]interface{}))))
- case *[]interface{}:
- list := data[k].([]interface{})
- sortedData += fmt.Sprintf(`"%s":[`, k)
- for j, item := range list {
- if j > 0 {
- sortedData += ","
- }
- sortedData += sortMapByKey(item.(map[string]interface{}))
- }
- sortedData += "]"
- default:
- sortedData += fmt.Sprintf(`"%s":%v`, k, reflect.ValueOf(data[k]).Elem())
- }
- } else {
- switch data[k].(type) {
- case string:
- sortedData += fmt.Sprintf(`"%s":"%s"`, k, data[k].(string))
- case map[string]interface{}:
- sortedData += fmt.Sprintf(`"%s":%s`, k, sortMapByKey(data[k].(map[string]interface{})))
- case []interface{}:
- list := data[k].([]interface{})
- sortedData += fmt.Sprintf(`"%s":[`, k)
- for j, item := range list {
- if j > 0 {
- sortedData += ","
- }
- sortedData += sortMapByKey(item.(map[string]interface{}))
- }
- sortedData += "]"
- default:
- sortedData += fmt.Sprintf(`"%s":%v`, k, data[k])
- }
- }
- }
- return fmt.Sprintf("{%s}", sortedData)
- }
|