AdaPayController.php 2.5 KB

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