TongueController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\index\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Config;
  5. use app\model\Tongue;
  6. class TongueController extends Base
  7. {
  8. public function check()
  9. {
  10. $uid = UID();
  11. $weid = weid();
  12. /*
  13. $data = Tongue::where(['uid' => $uid, 'weid' => $weid])->find();
  14. if (!empty($data)) {
  15. $data = $data->toArray();
  16. }
  17. */
  18. return $this->json(['data' => $data]);
  19. }
  20. public function upload()
  21. {
  22. $uid = UID();
  23. $weid = weid();
  24. $tongueConfig = Config::getconfig('tongue');
  25. $img = input('post.img', '', 'serach_in');
  26. //$tongue = Tongue::where('uid', $uid)->find();
  27. if (empty($tongue)) {
  28. $tongue = Tongue::create([
  29. 'uid' => $uid,
  30. 'weid' => $weid,
  31. 'price' => $tongueConfig['price'],
  32. 'is_pay' => 0,
  33. 'img' => $img,
  34. 'status' => 1
  35. ]);
  36. } else {
  37. Tongue::where('id', $tongue->id)->update(['img' => $img]);
  38. }
  39. $tongue = $tongue->toArray();
  40. return $this->json(['data' => $tongue]);
  41. }
  42. public function getaidata()
  43. {
  44. $id = (int) input('post.id', '', 'serach_in');
  45. $tongue = Tongue::find($id);
  46. if (!empty($tongue)) {
  47. $tongue = $tongue->toArray();
  48. if (empty($tongue['bodydata']) && !empty($tongue['img'])) {
  49. $tongueConfig = Config::getconfig('tongue');
  50. $url = 'http://www.aibayes.cn/api/analysis';
  51. $restime = date("YmdHis");
  52. $appid = trim($tongueConfig['app_id']);
  53. $key = trim($tongueConfig['apikey']);
  54. $postparam = [
  55. 'timestamp' => $restime,
  56. 'app_id' => $appid,
  57. 'version' => '1.0',
  58. 'method' => 'jiuti',
  59. 'imgpath' => $tongue['img'],
  60. 'sign' => strtoupper(md5(strtoupper(md5($restime)) . $key)),
  61. 'timeout_express' => 60
  62. ];
  63. $ret = Author()::postbyform($url, $postparam);
  64. if ($ret['code'] == 200) {
  65. Tongue::where('id', $tongue['id'])->update(['bodydata' => ($ret['data'])]);
  66. }
  67. $data = json_decode($ret['data'], true);
  68. }else{
  69. $data = json_decode($tongue['bodydata'], true);
  70. }
  71. }
  72. return $this->json(['data' => $data]);
  73. }
  74. }