生成书籍访问的二维码.
()
| 1386 | //生成书籍访问的二维码. |
| 1387 | |
| 1388 | func (this *DocumentController) QrCode() { |
| 1389 | this.Prepare() |
| 1390 | identify := this.GetString(":key") |
| 1391 | |
| 1392 | book, err := models.NewBook().FindByIdentify(identify) |
| 1393 | |
| 1394 | if err != nil || book.BookId <= 0 { |
| 1395 | this.Abort("404") |
| 1396 | } |
| 1397 | |
| 1398 | uri := this.BaseUrl() + beego.URLFor("DocumentController.Index", ":key", identify) |
| 1399 | code, err := qr.Encode(uri, qr.L, qr.Unicode) |
| 1400 | if err != nil { |
| 1401 | beego.Error(err) |
| 1402 | this.Abort("404") |
| 1403 | } |
| 1404 | code, err = barcode.Scale(code, 150, 150) |
| 1405 | |
| 1406 | if err != nil { |
| 1407 | beego.Error(err) |
| 1408 | this.Abort("404") |
| 1409 | } |
| 1410 | this.Ctx.ResponseWriter.Header().Set("Content-Type", "image/png") |
| 1411 | |
| 1412 | //imgpath := filepath.Join("cache","qrcode",identify + ".png") |
| 1413 | |
| 1414 | err = png.Encode(this.Ctx.ResponseWriter, code) |
| 1415 | if err != nil { |
| 1416 | beego.Error(err) |
| 1417 | this.Abort("404") |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | // 书籍内搜索. |
| 1422 | func (this *DocumentController) Search() { |
nothing calls this directly
no test coverage detected