LgApplyNotifyController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\common\controllers;
  8. use app\models\Lg;
  9. use app\models\ReOrder;
  10. use app\modules\common\models\NotifyForm;
  11. use app\utils\LgApi;
  12. use app\utils\OrderNo;
  13. use app\utils\Wechat\Wechat;
  14. use app\utils\Wechat\WechatProfit;
  15. use app\utils\Wechat\WechatShare;
  16. use EasyWeChat\Kernel\Exceptions\Exception;
  17. use EasyWeChat\Kernel\BaseClient;
  18. use yii\web\Controller;
  19. use app\utils\IotCloudHelper;
  20. use app\models\Store;
  21. use app\models\OrderUnion;
  22. use app\models\Order;
  23. use app\models\WechatConfig;
  24. class LgApplyNotifyController extends Controller
  25. {
  26. /**
  27. * 入口文件
  28. * @throws \Exception
  29. */
  30. public function actionIndex() {
  31. $store_id = get_params('store_id');
  32. $res = file_get_contents('php://input');
  33. $data = json_decode($res,true);
  34. $store = Store::findOne($store_id);
  35. $data = json_decode(self::decrypt($data['bizContent'],$store->lg_key),true);
  36. if ($data['status'] == 300){
  37. //成功
  38. $lg_user = Lg::find()->where(['cert_card'=>$data['certCard'],'is_delete'=>0])->andWhere(['!=','status',1])->one();
  39. $lg_user->status = 1;
  40. $lg_user->updated_at = time();
  41. $lg_user->save();
  42. }
  43. if ($data['status'] == 999){
  44. //失败
  45. $lg_user = Lg::find()->where(['cert_card'=>$data['certCard'],'is_delete'=>0])->andWhere(['!=','status',1])->one();
  46. $lg_user->status = 2;
  47. $lg_user->updated_at = time();
  48. $lg_user->refuse_desc = $data['msg'];
  49. $lg_user->save();
  50. }
  51. }
  52. public static function decrypt($encryptData,$key){
  53. $privateKey = openssl_pkey_get_private(self::formatterPrivateKey($key));
  54. $privateKey or die('密钥不可用');
  55. $decryptData = '';
  56. $crypto = '';
  57. $ed = str_split(base64_decode($encryptData),256);
  58. foreach ($ed as $chunk) {
  59. if(openssl_private_decrypt($chunk, $decryptData, $privateKey)){
  60. $crypto .= $decryptData;
  61. }else{
  62. die('解密失败');
  63. }
  64. }
  65. return $crypto;
  66. }
  67. /**
  68. * 格式化私钥
  69. * @param $priKey string 私钥
  70. * @return string
  71. */
  72. public static function formatterPrivateKey($priKey)
  73. {
  74. $res = "-----BEGIN RSA PRIVATE KEY-----\n" .
  75. wordwrap($priKey, 64, "\n", true) .
  76. "\n-----END RSA PRIVATE KEY-----";
  77. return $res;
  78. }
  79. }