PayChannelCheck.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Modules\Channel\Services\ChannelService;
  5. use App\Libs\Pay\WechatPay;
  6. use DB;
  7. use App\Libs\SMS;
  8. use App\Libs\Pay\Merchants\AllinPay;
  9. use App\Libs\PayClient;
  10. class PayChannelCheck extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'pay:check';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = '支付通道检测报警切换';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return mixed
  37. */
  38. public function handle()
  39. {
  40. $this->start();
  41. }
  42. public function start(){
  43. $res = $this->getPayChannel();
  44. print_r($res);
  45. if(empty($res)){
  46. //$this->sendMsg();
  47. //$this->changechannel();
  48. }
  49. }
  50. private function getPayChannel(){
  51. $channel = ChannelService::getById(5);
  52. $pay_merchant = DB::table('pay_merchants')->select('appid','source','config_info')->where('id',$channel->pay_merchant_id)->where('is_enabled',1)->first();
  53. $config = json_decode($pay_merchant->config_info,true);
  54. $wechatPay = WechatPay::instance($pay_merchant->source,$config);
  55. $data = [
  56. 'body'=>'novel buy',
  57. 'detail'=>'novel buy',
  58. 'trade_no'=>date("YmdHis").'check',
  59. 'openid'=>'oEteU1USo_yaT0NzA4QttI6Tl7gU',
  60. 'price'=>1,
  61. 'create_ip'=>'47.96.174.172',
  62. 'remark'=>json_encode(
  63. [
  64. 'uid'=>13,
  65. 'dcd'=>5,
  66. 'bid'=>0,
  67. 'cp'=>'47.96.174.172',
  68. 'pms'=>$pay_merchant->source,
  69. 'pmi'=>$channel->pay_merchant_id,
  70. 'pd'=>1,
  71. 'soi'=>1,
  72. ]
  73. )
  74. ];
  75. $pay_info = $wechatPay->send($data);
  76. return $pay_info;
  77. }
  78. private function changechannel(){
  79. DB::table('distribution_channels')->where('phone','!=','')->update(['pay_merchant_id'=>3]);
  80. }
  81. private function sendMsg(){
  82. //$phone_arr = ['15868100210','18072713392','15088790066','13706510321','13858057394','18668029091'];
  83. $phone_arr = ['18668029091'];
  84. foreach ($phone_arr as $phone){
  85. SMS::send($phone,'支付通道已经切换到官方支付了');
  86. }
  87. }
  88. public function payChannelSend($type,$config){
  89. switch ($type){
  90. case 'ALLINPAY':
  91. $wechatPay = new AllinPay($config);
  92. break;
  93. }
  94. }
  95. }