AdaPayController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\api\controller;
  3. use AdaPay\AdaTools;
  4. use app\models\article\ArticleContent;
  5. use app\models\store\StoreOrder;
  6. use app\models\user\UserRecharge;
  7. use app\Request;
  8. use crmeb\services\UtilService;
  9. include_once dirname(__FILE__). "/AdapayCore/utils/AdaTools.php";
  10. /**
  11. *
  12. * Class DouYiCantroller
  13. * @package app\api\controller
  14. */
  15. class AdaPayController
  16. {
  17. public $rsaPublicKeyFilePath = "";
  18. public $rsaPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwN6xgd6Ad8v2hIIsQVnbt8a3JituR8o4Tc3B5WlcFR55bz4OMqrG/356Ur3cPbc2Fe8ArNd/0gZbC9q56Eb16JTkVNA/fye4SXznWxdyBPR7+guuJZHc/VW2fKH2lfZ2P3Tt0QkKZZoawYOGSMdIvO+WqK44updyax0ikK6JlNQIDAQAB";
  19. public function notify(Request $request)
  20. {
  21. $post = $request->post();
  22. $data = json_decode($post['data']);
  23. $sing = $post['sign'];
  24. $res = $this->verifySign($sing, $post['data']);
  25. if($res){
  26. $order = strstr($data->order_no, '-', -1);
  27. $res = StoreOrder::paySuccess($order, $data->pay_channel);
  28. if ($res){
  29. echo '200';
  30. exit();
  31. }
  32. }else {
  33. echo 'error';
  34. exit();
  35. }
  36. }
  37. public function cz_notify(Request $request)
  38. {
  39. $post = $request->post();
  40. $data = json_decode($post['data']);
  41. $sing = $post['sign'];
  42. $res = $this->verifySign($sing, $post['data']);
  43. if($res){
  44. $order = strstr($data->order_no, '-', -1);
  45. $res = UserRecharge::rechargeSuccess($order);
  46. if ($res){
  47. echo '200';
  48. exit();
  49. }
  50. }else {
  51. echo 'error';
  52. exit();
  53. }
  54. }
  55. public function checkEmpty($value) {
  56. if (!isset($value))
  57. return true;
  58. if ($value === null)
  59. return true;
  60. if (trim($value) === "")
  61. return true;
  62. return false;
  63. }
  64. public function verifySign($signature, $data){
  65. if($this->checkEmpty($this->rsaPublicKeyFilePath)){
  66. $pubKey=$this->rsaPublicKey;
  67. $key = "-----BEGIN PUBLIC KEY-----\n".wordwrap($pubKey, 64, "\n", true)."\n-----END PUBLIC KEY-----";
  68. }else {
  69. $pubKey = file_get_contents($this->rsaPublicKeyFilePath);
  70. $key = openssl_get_publickey($pubKey);
  71. }
  72. if (openssl_verify($data, base64_decode($signature), $key)){
  73. return true;
  74. }else{
  75. return false;
  76. }
  77. }
  78. }