Pay.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace Journal\Lib;
  3. use Dever;
  4. class Pay
  5. {
  6. /**
  7. * 支付成功后,调取的接口
  8. *
  9. * @return mixed
  10. */
  11. public function act_api($param = array())
  12. {
  13. $send = Dever::preInput('pay_');
  14. $key = md5('jmss_2018');
  15. ksort($send);
  16. $send['signature'] = md5($key . '&' . http_build_query($send));
  17. $signature = Dever::input('signature');
  18. if ($send['signature'] == $signature) {
  19. $product_id = $send['pay_product_id'];
  20. $uid = $send['pay_uid'];
  21. $cash = $send['pay_cash'];
  22. $order_id = $send['pay_order_id'];
  23. $status = $send['pay_status'];
  24. $msg = $send['pay_msg'];
  25. $order = Dever::db('journal/order')->one(array('order_id' => $order_id, 'uid' => $uid));
  26. if ($send['pay_status'] == 2 && $order) {
  27. $update = array();
  28. $update['where_id'] = $order['id'];
  29. $update['status'] = 2;
  30. if ($order['type'] == 3) {
  31. # 购买兑换码
  32. $product_num = 1;
  33. if ($order['buy_id'] > 0) {
  34. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  35. $product_num = $buy['num'];
  36. }
  37. $update['code'] = Dever::load('code/lib/core')->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $uid);
  38. }
  39. Dever::db('journal/order')->update($update);
  40. if ($order['type'] != 1) {
  41. return;
  42. }
  43. # 订阅
  44. Dever::load('act/lib/subscribe')->submit($uid, $order['product_id'], 1);
  45. $score = false;
  46. $num = false;
  47. if ($order['buy_id'] > 0) {
  48. $info = Dever::db('journal/info')->one($order['product_id']);
  49. $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
  50. if ($info && $buy && $info['score'] > 0) {
  51. $score = $buy['num'] * $info['score'];
  52. } elseif ($info && $buy) {
  53. $num = $buy['num'];
  54. }
  55. }
  56. Dever::score($uid, 'buy_journal', '购买小刊', 'act/lib/score.submit?method=pay&type=4&id=' . $order['product_id'], $score, $num);
  57. # 发消息
  58. $journal = Dever::db('journal/info')->one($order['product_id']);
  59. if (Dever::project('message')) {
  60. Dever::load('message/lib/data')->push(-1, $uid, '购买提醒', '购买成功,您获得了 '.$journal['name'].' 的阅读资格!', 11, $order['cate_id']);
  61. }
  62. $user = Dever::db('passport/user')->one($uid);
  63. # 发短信
  64. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms') && $order['cate_id'] == 1) {
  65. $send = array();
  66. $send['name'] = $journal['name'];
  67. Dever::load('sms/api.send', 'buy_journal', $user['mobile'], $send);
  68. }
  69. # 发模板消息
  70. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => $order['cate_id']));
  71. if ($wechat && Dever::project('wechat_applet')) {
  72. $send['key'] = 'buy_journal';
  73. $send['project_id'] = $order['cate_id'];
  74. $send['touser'] = $wechat['openid'];
  75. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  76. $send['data'] = array
  77. (
  78. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  79. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  80. );
  81. $send['data'] = json_encode($send['data']);
  82. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  83. if ($send['form_id']) {
  84. Dever::load('wechat_applet/msg.send', $send);
  85. }
  86. }
  87. } else {
  88. Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 3));
  89. }
  90. }
  91. }
  92. public function send_api()
  93. {
  94. $uid = Dever::input('uid', 8);
  95. # 发模板消息
  96. $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid));
  97. if ($wechat && Dever::project('wechat_applet')) {
  98. $send['key'] = 'buy_journal';
  99. $send['project_id'] = 2;
  100. $send['touser'] = $wechat['openid'];
  101. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
  102. $send['data'] = array
  103. (
  104. 'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
  105. 'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
  106. );
  107. $send['data'] = json_encode($send['data']);
  108. $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
  109. if ($send['form_id']) {
  110. Dever::load('wechat_applet/msg.send', $send);
  111. }
  112. }
  113. }
  114. }