PHP code example of yonghua4413 / wxpay

1. Go to this page and download the library: Download yonghua4413/wxpay library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yonghua4413 / wxpay example snippets


//加载
use YYHwxpay\Wxpay;

//准备订单信息
$order_id = data('YmdHis').mt_rand(1000,9999);
$openid = ''; //自行获取用户openid
$ip = ''; //自行获取ip
$pay_param = array(
    'body' => '一分钱测试商品',
    'out_trade_no' => $order_id,
    'spbill_create_ip' => $ip,
    'total_fee' => 1,
    'notify_url' => '' //异步通知地址
);

//将订单提交到数据库(代码略);

//自行申请
$config => array(
    'app_id'   => '',
    'app_secret'    => '',
    'app_mchid'=>'',
    'key' => ''
);

//调用统一下单
$weixin = new Wxpay($config);
$response = $weixin -> create_order($pay_param);

//发生错误
if($response['error'] == 1){
    var_dump($response['msg']);exit;
}

//扫码自付 获取支付二维码地址,自行调用相关类库生成二维码
$code_url = $response['data']['code_url'];
//扫码支付结束

//jspai支付 需要在config指定类型 'type' => "JSAPI"
$sign = $weixin -> get_jsbridge_param($response['data']['prepay_id']);

//页面端(jsapi支付)
<script type="text/javascript">
$('#pay').on('click', function(){
	function onBridgeReady(){
	    WeixinJSBridge.invoke(
		'getBrandWCPayRequest', {
		    "appId":" echo $sign['appId']