|
| 1 | +package WeChatCustomerServiceSDK |
| 2 | + |
| 3 | +import ( |
| 4 | + "WeChatCustomerServiceSDK/util" |
| 5 | + "encoding/json" |
| 6 | + "errors" |
| 7 | + "fmt" |
| 8 | +) |
| 9 | + |
| 10 | +const ( |
| 11 | + //添加客服账号 |
| 12 | + accountAddAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/account/add?access_token=%s" |
| 13 | + // 删除客服账号 |
| 14 | + accountDelAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/account/del?access_token=%s" |
| 15 | + // 修改客服账号 |
| 16 | + accountUpdateAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/account/update?access_token=%s" |
| 17 | + // 获取客服账号列表 |
| 18 | + accountListAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/account/list?access_token=%s" |
| 19 | + //获取客服账号链接 |
| 20 | + addContactWayAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/add_contact_way?access_token=%s" |
| 21 | +) |
| 22 | + |
| 23 | +// AccountAddOptions 添加客服账号请求参数 |
| 24 | +type AccountAddOptions struct { |
| 25 | + Name string `json:"name"` // 客服帐号名称, 不多于16个字符 |
| 26 | + MediaID string `json:"media_id"` // 客服头像临时素材。可以调用上传临时素材接口获取, 不多于128个字节 |
| 27 | +} |
| 28 | + |
| 29 | +// AccountAddSchema 添加客服账号响应内容 |
| 30 | +type AccountAddSchema struct { |
| 31 | + BaseModel |
| 32 | + OpenKFID string `json:"open_kfid"` // 新创建的客服张号ID |
| 33 | +} |
| 34 | + |
| 35 | +// AccountAdd 添加客服账号 |
| 36 | +func (r *Client) AccountAdd(options AccountAddOptions) (info AccessTokenSchema, err error) { |
| 37 | + data, err := util.HttpPost(fmt.Sprintf(accountAddAddr, r.accessToken), options) |
| 38 | + if err != nil { |
| 39 | + return info, err |
| 40 | + } |
| 41 | + _ = json.Unmarshal(data, &info) |
| 42 | + if info.ErrCode != 0 { |
| 43 | + return info, errors.New(info.ErrMsg) |
| 44 | + } |
| 45 | + return info, nil |
| 46 | +} |
| 47 | + |
| 48 | +// AccountDelOptions 删除客服账号请求参数 |
| 49 | +type AccountDelOptions struct { |
| 50 | + OpenKFID string `json:"open_kfid"` // 客服帐号ID, 不多于64字节 |
| 51 | +} |
| 52 | + |
| 53 | +// AccountDel 删除客服账号 |
| 54 | +func (r *Client) AccountDel(options AccountDelOptions) (info BaseModel, err error) { |
| 55 | + data, err := util.HttpPost(fmt.Sprintf(accountDelAddr, r.accessToken), options) |
| 56 | + if err != nil { |
| 57 | + return info, err |
| 58 | + } |
| 59 | + _ = json.Unmarshal(data, &info) |
| 60 | + if info.ErrCode != 0 { |
| 61 | + return info, errors.New(info.ErrMsg) |
| 62 | + } |
| 63 | + return info, nil |
| 64 | +} |
| 65 | + |
| 66 | +// AccountUpdateOptions 修改客服账号请求参数 |
| 67 | +type AccountUpdateOptions struct { |
| 68 | + OpenKFID string `json:"open_kfid"` // 客服帐号ID, 不多于64字节 |
| 69 | + Name string `json:"name"` // 客服帐号名称, 不多于16个字符 |
| 70 | + MediaID string `json:"media_id"` // 客服头像临时素材。可以调用上传临时素材接口获取, 不多于128个字节 |
| 71 | +} |
| 72 | + |
| 73 | +// AccountUpdate 修复客服账号 |
| 74 | +func (r *Client) AccountUpdate(options AccountUpdateOptions) (info BaseModel, err error) { |
| 75 | + data, err := util.HttpPost(fmt.Sprintf(accountUpdateAddr, r.accessToken), options) |
| 76 | + if err != nil { |
| 77 | + return info, err |
| 78 | + } |
| 79 | + _ = json.Unmarshal(data, &info) |
| 80 | + if info.ErrCode != 0 { |
| 81 | + return info, errors.New(info.ErrMsg) |
| 82 | + } |
| 83 | + return info, nil |
| 84 | +} |
| 85 | + |
| 86 | +// AccountInfoSchema 客服详情 |
| 87 | +type AccountInfoSchema struct { |
| 88 | + OpenKFID string `json:"open_kfid"` // 客服帐号ID, 不多于64字节 |
| 89 | + Name string `json:"name"` // 客服帐号名称, 不多于16个字符 |
| 90 | + MediaID string `json:"media_id"` // 客服头像临时素材。可以调用上传临时素材接口获取, 不多于128个字节 |
| 91 | +} |
| 92 | + |
| 93 | +// AccountListSchema 获取客服账号列表响应内容 |
| 94 | +type AccountListSchema struct { |
| 95 | + BaseModel |
| 96 | + AccountList []AccountInfoSchema `json:"account_list"` // 客服账号列表 |
| 97 | +} |
| 98 | + |
| 99 | +// AccountList 获取客服账号列表 |
| 100 | +func (r *Client) AccountList() (info AccountListSchema, err error) { |
| 101 | + data, err := util.HttpGet(fmt.Sprintf(accountListAddr, r.accessToken)) |
| 102 | + if err != nil { |
| 103 | + return info, err |
| 104 | + } |
| 105 | + _ = json.Unmarshal(data, &info) |
| 106 | + if info.ErrCode != 0 { |
| 107 | + return info, errors.New(info.ErrMsg) |
| 108 | + } |
| 109 | + return info, nil |
| 110 | +} |
| 111 | + |
| 112 | +// AddContactWayOptions 获取客服账号链接 |
| 113 | +type AddContactWayOptions struct { |
| 114 | + OpenKFID string `json:"open_kfid"` // 客服帐号ID, 不多于64字节 |
| 115 | + Scene string `json:"scene"` // 场景值,字符串类型,由开发者自定义, 不多于32字节, 字符串取值范围(正则表达式):[0-9a-zA-Z_-]* |
| 116 | +} |
| 117 | + |
| 118 | +// AddContactWaySchema 获取客服账号链接响应内容 |
| 119 | +type AddContactWaySchema struct { |
| 120 | + BaseModel |
| 121 | + URL string `json:"url"` // 客服链接,开发者可将该链接嵌入到H5页面中,用户点击链接即可向对应的微信客服帐号发起咨询。开发者也可根据该url自行生成需要的二维码图片 |
| 122 | +} |
| 123 | + |
| 124 | +// AddContactWay 获取客服账号链接 |
| 125 | +func (r *Client) AddContactWay(options AddContactWayOptions) (info AddContactWaySchema, err error) { |
| 126 | + data, err := util.HttpPost(fmt.Sprintf(addContactWayAddr, r.accessToken), options) |
| 127 | + if err != nil { |
| 128 | + return info, err |
| 129 | + } |
| 130 | + _ = json.Unmarshal(data, &info) |
| 131 | + if info.ErrCode != 0 { |
| 132 | + return info, errors.New(info.ErrMsg) |
| 133 | + } |
| 134 | + return info, nil |
| 135 | +} |
0 commit comments