| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace addons\YunfastPay\common\services;
- use addons\YunfastPay\common\utils\Des3Utils;
- use Exception;
- use Yii;
- use yii\helpers\Json;
- /**
- * 回调通知处理
- * @package addons\YunfastPay\common\services
- */
- class NotifyService extends BaseService
- {
- /**
- * 通知信息
- *
- * @param string $msg
- * @return boolean
- */
- public function check(string $msg, string $type)
- {
- $config = (new SettingService([
- 'mall_id' => $this->mall_id,
- ]))->getSetting();
- try {
- $reqStr = Des3Utils::decrypt($msg, $config['secret']);
- Yii::error('$reqStr' . $reqStr);
- $respData = Json::decode($reqStr);
- Yii::error('$respData' . $respData);
- // 添加日志
- $this->addFileLog($msg, $config['secret'], $respData);
- // 处理支付回调
- if ($type == 'pay') {
- $service = new PayService(['mall_id' => $this->mall_id]);
- return $service->notify($respData);
- }
- // 处理代付回调
- if ($type == 'agent') {
- $service = new AgentService(['mall_id' => $this->mall_id]);
- return $service->notify($respData);
- }
- if ($type == 'refund') {
- $service = new RefundService(['mall_id' => $this->mall_id]);
- return $service->notify($respData);
- }
- } catch (Exception $e) {
- Yii::error('银典支付回调异常: ' . $e->getMessage());
- return $this->error($e->getMessage());
- }
- }
- /**
- * 添加文件日志
- *
- * @param string $msg
- * @param string $secret
- * @param array $data
- * @return void
- */
- public function addFileLog(string $msg, string $secret, array $data)
- {
- file_put_contents('./yunfast.log', Json::encode([
- 'mall_id' => $this->mall_id,
- 'msg' => $msg,
- 'secret' => $secret,
- 'data' => $data,
- ]) . "\r", FILE_APPEND);
- }
- }
|