userid
This commit is contained in:
parent
f23e64d20b
commit
940a627ade
|
@ -103,6 +103,24 @@ func (q *App) GetResult(rspBody []byte) (map[string]interface{}, error) {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *App) GetOpenid(userid string) (string, error) {
|
||||||
|
if err := q.refreshToken(); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
reqUrl := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid?access_token=%s", q.GetToken())
|
||||||
|
rspBody, err := util.HttpPostJson(reqUrl, nil, []byte(fmt.Sprintf(`{"userid" : "%s"}`, userid)))
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("httpPost url[%s] error :%s", reqUrl, err.Error())
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
result, err := q.GetResult(rspBody)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return cast.ToString(result["openid"]), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (q *App) GetUserInfo(userid string) (*UserInfo, error) {
|
func (q *App) GetUserInfo(userid string) (*UserInfo, error) {
|
||||||
if err := q.refreshToken(); err != nil {
|
if err := q.refreshToken(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -22,7 +22,7 @@ import (
|
||||||
type PayReq struct {
|
type PayReq struct {
|
||||||
TotalAmount int64
|
TotalAmount int64
|
||||||
Title string
|
Title string
|
||||||
Userid string
|
Openid string
|
||||||
BillNo string
|
BillNo string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,24 +125,6 @@ func (w *AppPay) initPay() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *App) getOpenid(userid string) (string, error) {
|
|
||||||
if err := q.refreshToken(); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
reqUrl := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid?access_token=%s", q.GetToken())
|
|
||||||
rspBody, err := butil.HttpPostJson(reqUrl, nil, []byte(fmt.Sprintf(`{"userid" : "%s"}`, userid)))
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("httpPost url[%s] error :%s", reqUrl, err.Error())
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
result, err := q.GetResult(rspBody)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return cast.ToString(result["openid"]), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *AppPay) PayMoney(req *PayReq) error {
|
func (p *AppPay) PayMoney(req *PayReq) error {
|
||||||
if p.cli == nil {
|
if p.cli == nil {
|
||||||
if err := p.initPay(); err != nil {
|
if err := p.initPay(); err != nil {
|
||||||
|
@ -151,20 +133,16 @@ func (p *AppPay) PayMoney(req *PayReq) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
param := butil.NewParams()
|
param := butil.NewParams()
|
||||||
userOpenid, err := p.getOpenid(req.Userid)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("get openid error :%s", err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if req.BillNo == "" {
|
if req.BillNo == "" {
|
||||||
req.BillNo = fmt.Sprintf("QY%s%s", time.Now().Format("20060102150405"), butil.CutTail(req.Userid, 12))
|
req.BillNo = fmt.Sprintf("QY%s", time.Now().Format("20060102150405"))
|
||||||
}
|
}
|
||||||
param.Set("nonce_str", goutil.RandomStr(32))
|
param.Set("nonce_str", goutil.RandomStr(32))
|
||||||
param.Set("mch_billno", req.BillNo)
|
param.Set("mch_billno", req.BillNo)
|
||||||
param.Set("mch_id", p.config.MchId)
|
param.Set("mch_id", p.config.MchId)
|
||||||
param.Set("wxappid", p.config.Corpid)
|
param.Set("wxappid", p.config.Corpid)
|
||||||
param.Set("agentid", p.config.Agent)
|
param.Set("agentid", p.config.Agent)
|
||||||
param.Set("re_openid", userOpenid)
|
param.Set("re_openid", req.Openid)
|
||||||
param.Set("total_amount", cast.ToString(req.TotalAmount))
|
param.Set("total_amount", cast.ToString(req.TotalAmount))
|
||||||
param.Set("wishing", req.Title)
|
param.Set("wishing", req.Title)
|
||||||
param.Set("act_name", "企业红包")
|
param.Set("act_name", "企业红包")
|
||||||
|
|
Loading…
Reference in New Issue