WxSendMessageService.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Service\Weixin;
  3. use App\Service\Service;
  4. use Illuminate\Support\Facades\Log;
  5. class WxSendMessageService extends Service
  6. {
  7. public function sendSalaryMessage($data,$temple_id){
  8. list($status,$token) = (new WeixinService())->getToken();
  9. if(! $status) return [false,'TOKEN错误,发送失败!'];
  10. $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$token;
  11. foreach ($data as $value){
  12. $post = '{
  13. "touser":"'.$value['openid'].'",
  14. "template_id":"'.$temple_id.'",
  15. "url":"'.$value['url'].'",
  16. "data":{
  17. "thing1":{
  18. "value":"'.$value['emp_name'].'",
  19. "color":"#173177"
  20. },
  21. "amount2": {
  22. "value":"'.$value['amount'].'",
  23. "color":"#173177"
  24. },
  25. "time3": {
  26. "value":"'.$value['salary_time'].'",
  27. "color":"#173177"
  28. },
  29. "thing4":{
  30. "value":"'.$value['cagetoryanddepart'].'",
  31. "color":"#173177"
  32. }
  33. }
  34. }';
  35. $data = array('url'=>$url,'post'=>$post);
  36. $res = $this->curlOpen($url,['post'=>$post]);
  37. $res = json_decode($res,true);
  38. if(isset($res['errcode']) && $res['errcode'] == 0){
  39. }
  40. Log::channel('request')->info('request', ['res_send'=>$res]);
  41. }
  42. }
  43. }