PHPackages                             life2016/yii2-wxpay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. life2016/yii2-wxpay

ActiveLibrary[Payment Processing](/categories/payments)

life2016/yii2-wxpay
===================

Wechat office sdk with composer.json and psr4

1.1(10y ago)1178↓91.7%5PHPPHP &gt;=5.3.0

Since Jun 8Pushed 10y ago3 watchersCompare

[ Source](https://github.com/ran1990/yii2-wxpay)[ Packagist](https://packagist.org/packages/life2016/yii2-wxpay)[ RSS](/packages/life2016-yii2-wxpay/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

微信支付PHP SDK
===========

[](#微信支付php-sdk)

微信支付PHP SDK 优化版本，支持Composer, PSR4

**基于微信官方的SDK 改编而来**

- 生成支付二维码

```
       $notify = new NativePay();

       $url = $notify->GetPrePayUrl($product_id);
       return Html::img(QrCode::png($url,false,'L',6,0));

```

- 调用微信H5支付

```
 //统一下单

        $tools = new JsApiPay();

        $openId = $tools->GetOpenid();

        $input = new WxPayUnifiedOrder();
        $input->SetBody($body);
        $input->SetOut_trade_no($out_trade_no);//订单号
        $input->SetTotal_fee($total_fee * 100);//金额
        $input->SetTime_start(date("YmdHis"));
        $input->SetTime_expire(date("YmdHis", time() + 300));
        $input->SetNotify_url($notify_url);//异步通知
        $input->SetTrade_type("JSAPI");
        $input->SetOpenid($openid);
        $order = WxPayApi::unifiedOrder($input);
        try {
            $jsApiParameters = $tools->GetJsApiParameters($order);
        } catch (Exception $e) {
            throw  new NotFoundHttpException();
        }

       //调用H5支付
        return $this->controller->render('wxpay', [
            'jsApiParameters' => $jsApiParameters,
            'success_url' => $this->successUrl.$data->order_info_id,//支付成功跳转地址
            'fail_url'=>$this->failUrl,//取消支付跳转地址
        ]);

```

- 扫描支付（模式一）

```
  //服务层接收
  class NativeNotifyCallBack extends  WxPayNotify
    {
        public function unifiedorder($openId, $product_id)
        {
            //orderInfo 的order_id怎么获取

            // 获取订单信息
            $order_info = Payment::getOrderInfoByPramas(['order_info_id'=>$product_id]);

            //统一下单
            $input = new WxPayUnifiedOrder();
            $input->SetBody($body);
            //$input->SetAttach("test");
            $input->SetOut_trade_no($order_info->order_sn);
            $input->SetTotal_fee($order_info->order_amount * 100);
            //$input->SetTime_start(date("YmdHis"));
            //$input->SetTime_expire(date("YmdHis", time() + 600));
            //$input->SetGoods_tag("test");
            $input->SetNotify_url(\Yii::$app->params['wxpay']['notify_url']);
            $input->SetTrade_type("NATIVE");
            $input->SetOpenid($openId);
            $input->SetProduct_id($product_id);
            $result = WxPayApi::unifiedOrder($input);

            return $result;

        }

        public function NotifyProcess($data, &$msg)
        {
            //echo "处理回调";
            if(!array_key_exists("openid", $data) ||
                !array_key_exists("product_id", $data))
            {
                $msg = "回调数据异常";
                return false;
            }

            $openid = $data["openid"];
            $product_id = $data["product_id"];

            //统一下单
            $result = $this->unifiedorder($openid, $product_id);
            if(!array_key_exists("appid", $result) ||
                !array_key_exists("mch_id", $result) ||
                !array_key_exists("prepay_id", $result))
            {
                $msg = "统一下单失败";
                return false;
            }

            $this->SetData("appid", $result["appid"]);
            $this->SetData("mch_id", $result["mch_id"]);
            $this->SetData("nonce_str", WxPayApi::getNonceStr());
            $this->SetData("prepay_id", $result["prepay_id"]);
            $this->SetData("result_code", "SUCCESS");
            $this->SetData("err_code_des", "OK");

            return true;
        }
    }

    //控制器调用
        $notify = new NativeNotifyCallBack();
        $notify->Handle(true);

```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3674d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/96126fb674e49c89c16c8f6cf2c0fca53197b35ed04a77bc0a7f1a942d32fafe?d=identicon)[ran](/maintainers/ran)

---

Top Contributors

[![ran1990](https://avatars.githubusercontent.com/u/18184629?v=4)](https://github.com/ran1990 "ran1990 (6 commits)")

### Embed Badge

![Health badge](/badges/life2016-yii2-wxpay/health.svg)

```
[![Health](https://phpackages.com/badges/life2016-yii2-wxpay/health.svg)](https://phpackages.com/packages/life2016-yii2-wxpay)
```

###  Alternatives

[omnipay/coinbase

Coinbase driver for the Omnipay payment processing library

18570.2k1](/packages/omnipay-coinbase)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
