Skip to content

Commit

Permalink
+对话能力 - 为顾问分配客户
Browse files Browse the repository at this point in the history
  • Loading branch information
blusewang committed Jun 11, 2020
1 parent 29850eb commit 00d9531
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
51 changes: 49 additions & 2 deletions mp.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ type accessTokenRes struct {

// 获取access_token
func (m Mp) AuthToken() (rs accessTokenRes, err error) {
api := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%v&secret=%v", m.AppId, m.AppSecret)
api := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/token?"+
"grant_type=client_credential&appid=%v&secret=%v", m.AppId, m.AppSecret)
raw, err := get(api)
if err != nil {
return
Expand Down Expand Up @@ -421,7 +422,8 @@ func (m Mp) KfList() (rs KfListResp, err error) {
}

func (m Mp) KfUploadHeadImg(f io.Reader, kfAccount string) (err error) {
api := fmt.Sprintf("https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=%v&kf_account=%v",
api := fmt.Sprintf("https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?"+
"access_token=%v&kf_account=%v",
m.AccessToken, kfAccount)
body := &bytes.Buffer{}
w := multipart.NewWriter(body)
Expand Down Expand Up @@ -792,3 +794,48 @@ func (m *Mp) ShortUrl(lUrl string) (sUrl string, err error) {
sUrl = rs.ShortUrl
return
}

type Buyer struct {
OpenId string `json:"openid,omitempty"`
BuyerNickname string `json:"buyer_nickname,omitempty"`
}
type AddGuideBuyerReq struct {
GuideAccount string `json:"guide_account,omitempty"`
GuideOpenid string `json:"guide_openid,omitempty"`
Buyer
BuyerList []Buyer `json:"buyer_list,omitempty"`
}

func (a AddGuideBuyerReq) SelfTest() error {
if a.GuideAccount == "" && a.GuideOpenid == "" {
return errors.New("guide_account guide_openid 二者必有其一")
}
if a.OpenId == "" && a.BuyerList == nil {
return errors.New("openid buyer_list 二者必有其一")
}
if len(a.BuyerList) > 200 {
return errors.New("客户列表不超过200")
}
return nil
}

// 对话能力 - 为顾问分配客户
func (m *Mp) AddGuideBuyerRelation(req AddGuideBuyerReq) (res MpBaseResp, err error) {
if err = req.SelfTest(); err != nil {
return
}
var form = new(bytes.Buffer)
if err = json.NewEncoder(form).Encode(req); err != nil {
return
}
resp, err := http.Post(
fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/guide/addguidebuyerrelation?access_token=%v", m.AccessToken),
contentJson,
form,
)
if err != nil {
return
}
err = json.NewDecoder(resp.Body).Decode(&res)
return
}
11 changes: 11 additions & 0 deletions mp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,14 @@ func TestMpMessage_ShouldDecode(t *testing.T) {
_ = json.Unmarshal(raw, &msg2)
log.Println(msg2.MsgType, msg2.MsgId, msg2.MsgID)
}

func TestAddGuideBuyerReq(t *testing.T) {
var req AddGuideBuyerReq
req.GuideOpenid = "....."
req.BuyerList = []Buyer{
{"", ""},
}
log.Println(req.SelfTest())
raw, _ := json.Marshal(req)
log.Println(string(raw))
}

0 comments on commit 00d9531

Please sign in to comment.