api.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. require_once "LovelyCat.php";
  3. //普通实例化
  4. $lovelyCat = new lovelyCat();
  5. switch ($lovelyCat->type) {//以下仅展示几种常见的场景,其他的请自行根据实际自由发挥!
  6. case 100://私聊消息
  7. $lovelyCat->sendTextMsg("我收到了你的私聊消息:" . $lovelyCat->msg);
  8. break;
  9. case 200://群聊消息
  10. $lovelyCat->sendTextMsg("我收到了群聊消息:" . $lovelyCat->msg);
  11. break;
  12. case 400://新人入群
  13. //{
  14. // "group_wxid": "xxx@chatroom",
  15. // "group_name": "xxx",
  16. // "guest": [{
  17. // "wxid": "xxx",
  18. // "nickname": "xxx"
  19. // }],
  20. // "inviter": {
  21. // "wxid": "xxx",
  22. // "nickname": "xxx"
  23. // }
  24. //}
  25. $origin = json_decode($lovelyCat->msg, true);
  26. $msg = sprintf("%s拉了新人入群,撒花欢迎:%s!!", $origin['inviter']['nickname'], $origin['guest'][0]['nickname']);
  27. $lovelyCat->sendTextMsg($msg);
  28. break;
  29. case 410://有人退群
  30. //msg 消息体:
  31. //{
  32. // "member_wxid": "xxx",
  33. // "member_nickname": "xxx",
  34. // "group_wxid": "11111@chatroom",
  35. // "group_name": "xxx",
  36. // "timestamp": 1575890752
  37. //}
  38. $origin = json_decode($lovelyCat->msg, true);
  39. $msg = sprintf("万般留不住,%s终于还是走了~", $origin['member_nickname']);
  40. $lovelyCat->sendTextMsg($msg);
  41. break;
  42. case 500:
  43. //收到好友请求,自动同意好友申请
  44. $lovelyCat->agreeFriendVerify();
  45. break;
  46. case 600:
  47. //收到二维码转账
  48. //{
  49. // "to_wxid": "wxid_9c6d4r3taosh22",
  50. // "msgid": 1705897420,
  51. // "received_money_index": "1",
  52. // "money": "0.01",
  53. // "total_money": "0.01",
  54. // "remark": "",
  55. // "scene_desc": "个人收款完成",
  56. // "scene": 3,
  57. // "timestamp": 1575891497
  58. //}
  59. $origin = json_decode($lovelyCat->msg, true);
  60. $msg = sprintf("收到扫码转账,金额:%s元", $origin['money']);
  61. file_put_contents("receive_money.log", $msg . PHP_EOL, FILE_APPEND);
  62. //此处可以执行日志记录知道的操作
  63. break;
  64. case 700:
  65. //收到转账
  66. //{
  67. // "paysubtype": "3",
  68. // "is_arrived": 1,
  69. // "is_received": 1,
  70. // "receiver_pay_id": "1000050101201912090003409856290",
  71. // "payer_pay_id": "100005010119120900084341523899983197",
  72. // "money": "0.01",
  73. // "remark": "",
  74. // "robot_pay_id": "1000050101201912090003409856290",
  75. // "pay_id": "100005010119120900084341523899983197",
  76. // "update_msg": "receiver_pay_id、payer_pay_id属性为robot_pay_id、pay_id的新名字,内容是一样的,建议更换"
  77. //}
  78. $origin = json_decode($lovelyCat->msg, true);
  79. $msg = sprintf("我收到了你的转账,金额:%s元", $origin['money']);
  80. $lovelyCat->acceptTransfer();//同意接收转账
  81. $lovelyCat->sendTextMsg($msg);//发送回执
  82. break;
  83. default:
  84. echo "OK";
  85. break;
  86. }