- update wechatopen

master
李光春 1 year ago
parent 4f4201a9ca
commit c238ba648a

@ -39,7 +39,7 @@ require (
gorm.io/driver/mysql v1.5.0
gorm.io/driver/postgres v1.5.0
gorm.io/gen v0.3.22
gorm.io/gorm v1.25.0
gorm.io/gorm v1.25.1
xorm.io/builder v0.3.12
xorm.io/xorm v1.3.2
)

@ -827,8 +827,9 @@ gorm.io/gen v0.3.22/go.mod h1:dQcELeF/7Kf82M6AQF+O/rKT5r1sjv49TlGz0cerPn4=
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.24.3/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.0 h1:+KtYtb2roDz14EQe4bla8CbQlmb9dN3VejSai3lprfU=
gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.1 h1:nsSALe5Pr+cM3V1qwwQ7rOkw+6UeLrX5O4v3llhHa64=
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/hints v1.1.2 h1:b5j0kwk5p4+3BtDtYqqfY+ATSxjj+6ptPgVveuynn9o=
gorm.io/hints v1.1.2/go.mod h1:/ARdpUHAtyEMCh5NNi3tI7FsGh+Cj/MIUlvNxCNCFWg=
gorm.io/plugin/dbresolver v1.4.1 h1:Ug4LcoPhrvqq71UhxtF346f+skTYoCa/nEsdjvHwEzk=

@ -1,5 +1,5 @@
package go_library
func Version() string {
return "1.0.138"
return "1.0.139"
}

@ -27,9 +27,9 @@ func newCgiBinComponentApiComponentTokenResult(result CgiBinComponentApiComponen
func (c *Client) CgiBinComponentApiComponentToken(ctx context.Context, notMustParams ...gorequest.Params) (*CgiBinComponentApiComponentTokenResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
params.Set("component_appid", c.GetComponentAppId(ctx)) // 第三方平台appid
params.Set("component_appsecret", c.GetComponentAppSecret(ctx)) // 第三方平台appsecret
params.Set("component_verify_ticket", c.GetComponentVerifyTicket(ctx)) // 微信后台推送的ticket
params.Set("component_appid", c.GetComponentAppId(ctx)) // 第三方平台appid
params.Set("component_appsecret", c.GetComponentAppSecret(ctx)) // 第三方平台appsecret
params.Set("component_verify_ticket", GetComponentVerifyTicket(ctx, c)) // 微信后台推送的ticket
// 请求
request, err := c.request(ctx, apiUrl+"/cgi-bin/component/api_component_token", params, http.MethodPost)
if err != nil {

@ -5,86 +5,31 @@ import (
"github.com/dtapps/go-library/utils/golog"
)
// GetComponentAppId 获取第三方平台appid
// GetComponentAppId 第三方平台appid
func (c *Client) GetComponentAppId(ctx context.Context) string {
return c.config.componentAppId
}
// NewGetComponentAppId 获取第三方平台appid
func (c *Client) NewGetComponentAppId(ctx context.Context) string {
return c.config.componentAppId
}
// GetComponentAppSecret 获取第三方平台app_secret
// GetComponentAppSecret 第三方平台app_secret
func (c *Client) GetComponentAppSecret(ctx context.Context) string {
return c.config.componentAppSecret
}
// NewGetComponentAppSecret 获取第三方平台app_secret
func (c *Client) NewGetComponentAppSecret(ctx context.Context) string {
return c.config.componentAppSecret
}
// GetMessageToken 获取第三方平台消息令牌
// GetMessageToken 第三方平台消息令牌
func (c *Client) GetMessageToken(ctx context.Context) string {
return c.config.messageToken
}
// NewGetMessageToken 获取第三方平台消息令牌
func (c *Client) NewGetMessageToken(ctx context.Context) string {
return c.config.messageToken
}
// GetMessageKey 获取第三方平台消息密钥
// GetMessageKey 第三方平台消息密钥
func (c *Client) GetMessageKey(ctx context.Context) string {
return c.config.messageKey
}
// NewGetMessageKey 获取第三方平台消息密钥
func (c *Client) NewGetMessageKey(ctx context.Context) string {
return c.config.messageKey
}
// NewGetComponentAccessToken 获取第三方平台access_token
func (c *Client) NewGetComponentAccessToken(ctx context.Context) string {
return c.config.componentAccessToken
}
// GetComponentVerifyTicket 获取第三方平台推送ticket
func (c *Client) GetComponentVerifyTicket(ctx context.Context) string {
return c.config.componentVerifyTicket
}
// NewGetComponentVerifyTicket 获取第三方平台推送ticket
func (c *Client) NewGetComponentVerifyTicket(ctx context.Context) string {
return c.config.componentVerifyTicket
}
// NewGetPreAuthCode 获取第三方平台预授权码
func (c *Client) NewGetPreAuthCode(ctx context.Context) string {
return c.config.preAuthCode
}
// GetAuthorizerAppid 获取授权方appid
// GetAuthorizerAppid 授权方appid
func (c *Client) GetAuthorizerAppid(ctx context.Context) string {
return c.config.authorizerAppid
}
// NewGetAuthorizerAppid 获取授权方appid
func (c *Client) NewGetAuthorizerAppid(ctx context.Context) string {
return c.config.authorizerAppid
}
// NewGetAuthorizerAccessToken 获取授权方access_token
func (c *Client) NewGetAuthorizerAccessToken(ctx context.Context) string {
return c.config.authorizerAccessToken
}
// NewGetAuthorizerRefreshToken 获取授权方refresh_token
func (c *Client) NewGetAuthorizerRefreshToken(ctx context.Context) string {
return c.config.authorizerRefreshToken
}
func (c *Client) GetLog(ctx context.Context) *golog.ApiClient {
return c.log.client
}

@ -1,33 +0,0 @@
package wechatopen
import "context"
// NewSetComponentAccessToken 设置第三方平台access_token
func (c *Client) NewSetComponentAccessToken(ctx context.Context, componentAccessToken string) {
c.config.componentAccessToken = componentAccessToken
}
// NewSetComponentVerifyTicket 设置第三方平台推送ticket
func (c *Client) NewSetComponentVerifyTicket(ctx context.Context, componentVerifyTicket string) {
c.config.componentVerifyTicket = componentVerifyTicket
}
// NewSetPreAuthCode 设置第三方平台预授权码
func (c *Client) NewSetPreAuthCode(ctx context.Context, preAuthCode string) {
c.config.preAuthCode = preAuthCode
}
// NewSetAuthorizerAppid 设置授权方appid
func (c *Client) NewSetAuthorizerAppid(ctx context.Context, authorizerAppid string) {
c.config.authorizerAppid = authorizerAppid
}
// NewSetAuthorizerAccessToken 设置授权方access_token
func (c *Client) NewSetAuthorizerAccessToken(ctx context.Context, authorizerAccessToken string) {
c.config.authorizerAccessToken = authorizerAccessToken
}
// NewSetAuthorizerRefreshToken 设置授权方refresh_token
func (c *Client) NewSetAuthorizerRefreshToken(ctx context.Context, authorizerRefreshToken string) {
c.config.authorizerRefreshToken = authorizerRefreshToken
}

@ -14,6 +14,7 @@ import (
type Association struct {
DB *DB
Relationship *schema.Relationship
Unscope bool
Error error
}
@ -40,6 +41,15 @@ func (db *DB) Association(column string) *Association {
return association
}
func (association *Association) Unscoped() *Association {
return &Association{
DB: association.DB,
Relationship: association.Relationship,
Error: association.Error,
Unscope: true,
}
}
func (association *Association) Find(out interface{}, conds ...interface{}) error {
if association.Error == nil {
association.Error = association.buildCondition().Find(out, conds...).Error
@ -64,14 +74,30 @@ func (association *Association) Append(values ...interface{}) error {
func (association *Association) Replace(values ...interface{}) error {
if association.Error == nil {
reflectValue := association.DB.Statement.ReflectValue
rel := association.Relationship
var oldBelongsToExpr clause.Expression
// we have to record the old BelongsTo value
if association.Unscope && rel.Type == schema.BelongsTo {
var foreignFields []*schema.Field
for _, ref := range rel.References {
if !ref.OwnPrimaryKey {
foreignFields = append(foreignFields, ref.ForeignKey)
}
}
if _, fvs := schema.GetIdentityFieldValuesMap(association.DB.Statement.Context, reflectValue, foreignFields); len(fvs) > 0 {
column, values := schema.ToQueryValues(rel.FieldSchema.Table, rel.FieldSchema.PrimaryFieldDBNames, fvs)
oldBelongsToExpr = clause.IN{Column: column, Values: values}
}
}
// save associations
if association.saveAssociation( /*clear*/ true, values...); association.Error != nil {
return association.Error
}
// set old associations's foreign key to null
reflectValue := association.DB.Statement.ReflectValue
rel := association.Relationship
switch rel.Type {
case schema.BelongsTo:
if len(values) == 0 {
@ -91,6 +117,9 @@ func (association *Association) Replace(values ...interface{}) error {
association.Error = association.DB.UpdateColumns(updateMap).Error
}
if association.Unscope && oldBelongsToExpr != nil {
association.Error = association.DB.Model(nil).Where(oldBelongsToExpr).Delete(reflect.New(rel.FieldSchema.ModelType).Interface()).Error
}
case schema.HasOne, schema.HasMany:
var (
primaryFields []*schema.Field
@ -119,7 +148,11 @@ func (association *Association) Replace(values ...interface{}) error {
if _, pvs := schema.GetIdentityFieldValuesMap(association.DB.Statement.Context, reflectValue, primaryFields); len(pvs) > 0 {
column, values := schema.ToQueryValues(rel.FieldSchema.Table, foreignKeys, pvs)
association.Error = tx.Where(clause.IN{Column: column, Values: values}).UpdateColumns(updateMap).Error
if association.Unscope {
association.Error = tx.Where(clause.IN{Column: column, Values: values}).Delete(modelValue).Error
} else {
association.Error = tx.Where(clause.IN{Column: column, Values: values}).UpdateColumns(updateMap).Error
}
}
case schema.Many2Many:
var (
@ -184,7 +217,8 @@ func (association *Association) Delete(values ...interface{}) error {
switch rel.Type {
case schema.BelongsTo:
tx := association.DB.Model(reflect.New(rel.Schema.ModelType).Interface())
associationDB := association.DB.Session(&Session{})
tx := associationDB.Model(reflect.New(rel.Schema.ModelType).Interface())
_, pvs := schema.GetIdentityFieldValuesMap(association.DB.Statement.Context, reflectValue, rel.Schema.PrimaryFields)
if pcolumn, pvalues := schema.ToQueryValues(rel.Schema.Table, rel.Schema.PrimaryFieldDBNames, pvs); len(pvalues) > 0 {
@ -198,8 +232,21 @@ func (association *Association) Delete(values ...interface{}) error {
conds = append(conds, clause.IN{Column: relColumn, Values: relValues})
association.Error = tx.Clauses(conds...).UpdateColumns(updateAttrs).Error
if association.Unscope {
var foreignFields []*schema.Field
for _, ref := range rel.References {
if !ref.OwnPrimaryKey {
foreignFields = append(foreignFields, ref.ForeignKey)
}
}
if _, fvs := schema.GetIdentityFieldValuesMap(association.DB.Statement.Context, reflectValue, foreignFields); len(fvs) > 0 {
column, values := schema.ToQueryValues(rel.FieldSchema.Table, rel.FieldSchema.PrimaryFieldDBNames, fvs)
association.Error = associationDB.Model(nil).Where(clause.IN{Column: column, Values: values}).Delete(reflect.New(rel.FieldSchema.ModelType).Interface()).Error
}
}
case schema.HasOne, schema.HasMany:
tx := association.DB.Model(reflect.New(rel.FieldSchema.ModelType).Interface())
model := reflect.New(rel.FieldSchema.ModelType).Interface()
tx := association.DB.Model(model)
_, pvs := schema.GetIdentityFieldValuesMap(association.DB.Statement.Context, reflectValue, primaryFields)
if pcolumn, pvalues := schema.ToQueryValues(rel.FieldSchema.Table, foreignKeys, pvs); len(pvalues) > 0 {
@ -212,7 +259,11 @@ func (association *Association) Delete(values ...interface{}) error {
relColumn, relValues := schema.ToQueryValues(rel.FieldSchema.Table, rel.FieldSchema.PrimaryFieldDBNames, rvs)
conds = append(conds, clause.IN{Column: relColumn, Values: relValues})
association.Error = tx.Clauses(conds...).UpdateColumns(updateAttrs).Error
if association.Unscope {
association.Error = tx.Clauses(conds...).Delete(model).Error
} else {
association.Error = tx.Clauses(conds...).UpdateColumns(updateAttrs).Error
}
case schema.Many2Many:
var (
primaryFields, relPrimaryFields []*schema.Field

2
vendor/gorm.io/gorm/callbacks.go generated vendored

@ -249,7 +249,7 @@ func sortCallbacks(cs []*callback) (fns []func(*DB), err error) {
names, sorted []string
sortCallback func(*callback) error
)
sort.Slice(cs, func(i, j int) bool {
sort.SliceStable(cs, func(i, j int) bool {
if cs[j].before == "*" && cs[i].before != "*" {
return true
}

@ -234,7 +234,12 @@ func BuildQuerySQL(db *gorm.DB) {
fromClause.Joins = append(fromClause.Joins, genJoinClause(join.JoinType, parentTableName, rel))
specifiedRelationsName[nestedAlias] = nil
}
parentTableName = rel.Name
if parentTableName != clause.CurrentTable {
parentTableName = utils.NestedRelationName(parentTableName, rel.Name)
} else {
parentTableName = rel.Name
}
}
} else {
fromClause.Joins = append(fromClause.Joins, clause.Join{

@ -60,7 +60,7 @@ var tableRegexp = regexp.MustCompile(`(?i)(?:.+? AS (\w+)\s*(?:$|,)|^\w+\s+(\w+)
// Table specify the table you would like to run db operations
//
// // Get a user
// db.Table("users").take(&result)
// db.Table("users").Take(&result)
func (db *DB) Table(name string, args ...interface{}) (tx *DB) {
tx = db.getInstance()
if strings.Contains(name, " ") || strings.Contains(name, "`") || len(args) > 0 {

6
vendor/gorm.io/gorm/gorm.go generated vendored

@ -179,6 +179,12 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) {
if config.Dialector != nil {
err = config.Dialector.Initialize(db)
if err != nil {
if db, err := db.DB(); err == nil {
_ = db.Close()
}
}
}
preparedStmt := &PreparedStmtDB{

9
vendor/gorm.io/gorm/migrator.go generated vendored

@ -56,6 +56,14 @@ type Index interface {
Option() string
}
// TableType table type interface
type TableType interface {
Schema() string
Name() string
Type() string
Comment() (comment string, ok bool)
}
// Migrator migrator interface
type Migrator interface {
// AutoMigrate
@ -72,6 +80,7 @@ type Migrator interface {
HasTable(dst interface{}) bool
RenameTable(oldName, newName interface{}) error
GetTables() (tableList []string, err error)
TableType(dst interface{}) (TableType, error)
// Columns
AddColumn(dst interface{}, field string) error

@ -949,3 +949,8 @@ func (m Migrator) GetIndexes(dst interface{}) ([]gorm.Index, error) {
func (m Migrator) GetTypeAliases(databaseTypeName string) []string {
return nil
}
// TableType return tableType gorm.TableType and execErr error
func (m Migrator) TableType(dst interface{}) (gorm.TableType, error) {
return nil, errors.New("not support")
}

@ -0,0 +1,33 @@
package migrator
import (
"database/sql"
)
// TableType table type implements TableType interface
type TableType struct {
SchemaValue string
NameValue string
TypeValue string
CommentValue sql.NullString
}
// Schema returns the schema of the table.
func (ct TableType) Schema() string {
return ct.SchemaValue
}
// Name returns the name of the table.
func (ct TableType) Name() string {
return ct.NameValue
}
// Type returns the type of the table.
func (ct TableType) Type() string {
return ct.TypeValue
}
// Comment returns the comment of current table.
func (ct TableType) Comment() (comment string, ok bool) {
return ct.CommentValue.String, ct.CommentValue.Valid
}

@ -604,6 +604,22 @@ func (field *Field) setupValuerAndSetter() {
if data != nil && *data != nil {
field.ReflectValueOf(ctx, value).SetInt(**data)
}
case **int:
if data != nil && *data != nil {
field.ReflectValueOf(ctx, value).SetInt(int64(**data))
}
case **int8:
if data != nil && *data != nil {
field.ReflectValueOf(ctx, value).SetInt(int64(**data))
}
case **int16:
if data != nil && *data != nil {
field.ReflectValueOf(ctx, value).SetInt(int64(**data))
}
case **int32:
if data != nil && *data != nil {
field.ReflectValueOf(ctx, value).SetInt(int64(**data))
}
case int64:
field.ReflectValueOf(ctx, value).SetInt(data)
case int:
@ -668,6 +684,22 @@ func (field *Field) setupValuerAndSetter() {
if data != nil && *data != nil {
field.ReflectValueOf(ctx, value).SetUint(**data)
}
case **uint:
if data != nil && *data != nil {
field.ReflectValueOf(ctx, value).SetUint(uint64(**data))
}
case **uint8:
if data != nil && *data != nil {
field.ReflectValueOf(ctx, value).SetUint(uint64(**data))
}
case **uint16:
if data != nil && *data != nil {
field.ReflectValueOf(ctx, value).SetUint(uint64(**data))
}
case **uint32:
if data != nil && *data != nil {
field.ReflectValueOf(ctx, value).SetUint(uint64(**data))
}
case uint64:
field.ReflectValueOf(ctx, value).SetUint(data)
case uint:
@ -720,6 +752,10 @@ func (field *Field) setupValuerAndSetter() {
if data != nil && *data != nil {
field.ReflectValueOf(ctx, value).SetFloat(**data)
}
case **float32:
if data != nil && *data != nil {
field.ReflectValueOf(ctx, value).SetFloat(float64(**data))
}
case float64:
field.ReflectValueOf(ctx, value).SetFloat(data)
case float32:

@ -600,7 +600,7 @@ gorm.io/gen/internal/model
gorm.io/gen/internal/parser
gorm.io/gen/internal/template
gorm.io/gen/internal/utils/pools
# gorm.io/gorm v1.25.0
# gorm.io/gorm v1.25.1
## explicit; go 1.16
gorm.io/gorm
gorm.io/gorm/callbacks

Loading…
Cancel
Save