PHP 微信扫一扫支付(TP5)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Drug_/article/details/83869117

PHP交流群:294088839

1.支付调用

require_once "./payment/wxpay/php/lib/WxPay.Api.php";
require_once "./payment/wxpay/php/example/WxPay.NativePay.php";
$notify = new \NativePay();
$input = new \WxPayUnifiedOrder();
$input->SetBody("订单内容");
$input->SetOut_trade_no($order_data['order_number']);
$input->SetTotal_fee($zongMoney);
$input->SetTime_start(date("YmdHis"));
$input->SetNotify_url(config('u_wx_notify_url'));
$input->SetTrade_type("NATIVE");
$input->SetProduct_id(rand(10000,99999));

$result = $notify->GetPayUrl($input);

$url2 =config('prcode'). $result["code_url"];
2.微信支付识别二维码地址 这个在他的demo里有个qrcode 文件 
'prcode'=>'http://'.$_SERVER['HTTP_HOST'].'/payment/wxpay/php/example/qrcode.php?data='

3.参数配置 APPID等参数  在demo里的 WxPay.Config.php 进行配置 可以写一个构造函数 进行参数填写

private $appid;
private $mch_id;
private $key;
private $appsecret;
   public function __construct()
   {
       $pay=\think\Db::name('pay_type')->where(['pay_id'=>2])->field('pay_json')->find();
       $wx=json_decode($pay['pay_json'],true);
       $this->appid=$wx['web_appid'];
       $this->mch_id=$wx['web_mch_id'];
       $this->key=$wx['web_key'];
       $this->appsecret=$wx['web_appsecret'];

   }

4.微信回调地址 数据认证 

  $config = new \WxPayConfig();

  $notify = new \WxPayNotify();
  $notify->Handle($config, false);

  //存储微信的回调
  $objData = $GLOBALS['HTTP_RAW_POST_DATA'];
  //写入日志
  log_result("【接收到的notify通知】:\n".$objData."\n");
  $data=\WxPayResults::Init($config,$objData);
//  $data = $objData->GetValues();

  //TODO 1、进行参数校验
  if(!array_key_exists("return_code", $data) || (array_key_exists("return_code", $data) && $data['return_code'] != "SUCCESS")) {
      //TODO失败,不是支付成功的通知
      //如果有需要可以做失败时候的一些清理处理,并且做一些监控
      $msg = "异常异常";
      log_result("【接收到的notify通知】:\n".$msg."\n");
      return false;
  }
  if(!array_key_exists("transaction_id", $data)){
      $msg = "输入参数不正确";
      log_result("【接收到的notify通知】:\n".$msg."\n");
      return false;
  }

猜你喜欢

转载自blog.csdn.net/Drug_/article/details/83869117