AppletMessageNotice.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: yunzhong
  5. * Date: 2020/6/1
  6. * Time: 17:57
  7. */
  8. namespace app\common\services\notice\applet;
  9. use app\common\models\Member;
  10. use app\common\services\notice\BaseMessageNotice;
  11. class AppletMessageNotice extends BaseMessageNotice
  12. {
  13. public function __construct($temp_id, $openid = 0, $data, array $openids = [], $type,$url="")
  14. {
  15. parent::__construct($temp_id, $openid, $data, $openids, $type,$url);
  16. }
  17. public function sendMessage()
  18. {
  19. if (empty($this->options['app_id']) || empty($this->options['secret'])) {
  20. $this->back['status'] = 0;
  21. $this->back['message'] = "小程序配置错误";
  22. return $this->back;
  23. }
  24. if (empty($this->openid) && count($this->openids) <= 0) {
  25. $this->back['status'] = 0;
  26. $this->back['message'] = $this->openid."会员ID为空";
  27. return $this->back;
  28. }
  29. if (empty($this->template_id)) {
  30. $this->back['status'] = 0;
  31. $this->back['message'] = "模板ID为空";
  32. return $this->back;
  33. }
  34. if (!empty($this->openid)) {
  35. $official = $this->notice($this->openid);
  36. if ($official['status'] != 1) {
  37. return $official;
  38. }
  39. }
  40. if (!empty($this->openids)) {
  41. $msg = [];
  42. foreach ($this->openids as $kk=>$vv) {
  43. $rein = $this->notice($vv);
  44. if ($rein['status'] != 1) {
  45. $msg[] = $rein['message'];
  46. continue ;
  47. }
  48. }
  49. if (count($msg)>0) {
  50. $this->back['status'] = 0;
  51. $this->back['message'] = implode(',',$msg);
  52. return $this->back;
  53. }
  54. }
  55. $this->back['status'] = 1;
  56. $this->back['message'] = "";
  57. return $this->back;
  58. }
  59. }