12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package servers
- import (
- . "app.yhyue.com/moapp/jybase/api"
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/go-xweb/xweb"
- "fmt"
- "github.com/SKatiyar/qr"
- "jy-docs/config"
- "log"
- )
- type Share struct {
- *xweb.Action
- shareUrl xweb.Mapper `xweb:"/share/url"` //地址分享
- shareImg xweb.Mapper `xweb:"/share/img"` //链接分享
- }
- func (share *Share) ShareUrl() {
- userId := common.ObjToString(share.GetSession("userId"))
- rData, errMsg := func() (interface{}, error) {
- docId := share.GetString("docId") //分享地址
- return map[string]interface{}{
- "url": getShareUrl(userId, docId),
- }, nil
- }()
- if errMsg != nil {
- log.Printf("%s Share err:%s\n", errMsg.Error(), userId)
- }
- share.ServeJson(NewResult(rData, errMsg))
- }
- func (share *Share) ShareImg() {
- userId := common.ObjToString(share.GetSession("userId"))
- docId := share.GetString("docId") //分享地址
- data := getShareUrl(userId, docId)
- w := share.ResponseWriter
- w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
- w.Header().Set("Pragma", "no-cache")
- w.Header().Set("Expires", "0")
- w.Header().Set("Content-Type", "image/png")
- r, _ := qr.Encode(data, qr.M)
- _, _ = w.Write(r.PNG())
- }
- func getShareUrl(userId, docId string) string {
- return fmt.Sprintf(config.JyDocsAppConfig.ShareUrl+"?userId=%s", docId, userId)
- }
|