wechat pay
v1.0.0
composer require zhangv/wechat-pay
$ cfg = [
' mch_id ' => ' XXXX ' , //商户号
' app_id ' => ' XXXXXXXXXXXXXXXXXXX ' , //APPID
' app_secret ' => ' XXXXXXXXXXXXXXXXXXXXXXXXX ' , //App Secret
' api_key ' => ' XXXXXXXXXXXXXXXXXXXXXXX ' , //支付密钥
' ssl_cert_path ' => __DIR__ . ' /../cert/apiclient_cert.pem ' , //SSL证书(通过商户后台下载)
' ssl_key_path ' => __DIR__ . ' /../cert/apiclient_key.pem ' , //SSL密钥(通过商户后台下载)
' sign_type ' => ' MD5 ' ,
' notify_url ' => ' http://XXX.XXX/paidnotify.php ' , //支付结果通知地址
' refund_notify_url ' => ' http://XXX.XXX/refundednotify.php ' , //退款结果通知地址
' h5_scene_info ' => [ //H5支付时需要
' h5_info ' => [ ' type ' => ' Wap ' , ' wap_url ' => ' http://wapurl ' , ' wap_name ' => ' wapname ' ]
],
' rsa_pubkey_path ' => __DIR__ . ' /../cert/pubkey.pem ' ,
' jsapi_ticket ' => __DIR__ . ' /jsapi_ticket.json ' //jsticket的临时存放路径
];
$ wp = WechatPay:: Jsapi ( $ cfg );
$ prepayId = $ wp -> getPrepayId ( $ body , $ orderNo , $ amt , $ openid );
$ package = $ wp -> getPackage ( $ prepayId );
$ wp = WechatPay:: Weapp ( $ cfg );
$ prepayId = $ wp -> getPrepayId ( $ body , $ orderNo , $ amt , $ openid );
$ package = $ wp -> getPackage ( $ prepayId );
$ wp = WechatPay:: App ( $ cfg );
$ prepayId = $ wp -> getPrepayId ( $ body , $ orderNo , $ amt , $ openid );
$ package = $ wp -> getPackage ( $ prepayId );
$ wp = WechatPay:: Mweb ( $ cfg );
$ url = $ wp -> getMwebUrl ( $ body , $ orderNo , $ amt );
$ wp = WechatPay:: Native ( $ cfg );
$ url = $ wp -> getCodeUrl ( $ body , $ out_trade_no , $ total_fee , $ product_id );
$ wp = WechatPay:: Micro ( $ cfg );
$ url = $ wp -> microPay ( $ body , $ out_trade_no , $ total_fee , $ spbill_create_ip , $ auth_code );
$ notifyxml = file_get_contents ( " php://input " );
$ wp = new WechatPay ( $ cfg );
$ msg = $ wp -> onPaidNotify ( $ notifyxml , function ( $ notifyArray ){
//处理逻辑
return ' ok ' ;
});
$ xml = " <xml>
<return_code>SUCCESS</return_code>
<return_msg><![CDATA[ $ msg ]]></return_msg>
</xml> " ;
echo $ xml ;
$ wxpay = new WechatPay ( $ cfg );
$ result = $ wxpay -> refundByOutTradeNo ( $ out_trade_no , $ out_refund_no , $ total_fee , $ refund_fee );
$ wp = WechatPay:: Mchpay ( $ cfg );
//付款到零钱
$ result = $ wp -> transferWallet ( $ partner_trade_no , $ openid , $ amount , $ desc );
//付款到银行卡
$ result = $ wp -> transferBankCard ( $ partner_trade_no , $ bank_no , $ true_name , $ bank_code , $ amount , $ desc );
$ wp = WechatPay:: Redpack ( $ cfg );
//发放普通红包
$ result = $ wp -> sendRedPack ( $ mch_billno , $ send_name , $ re_openid , $ total_amount , $ total_num , $ wishing , $ act_name , $ remark );
//发放裂变红包
$ result = $ wp -> sendGroupRedPack ( $ mch_billno , $ send_name , $ re_openid , $ total_amount , $ total_num , $ wishing , $ act_name , $ remark );
$ wp = WechatPay:: Coupon ( $ cfg );
//发放代金券
$ result = $ wp -> sendCoupon ( $ coupon_stock_id , $ open_id , $ partner_trade_no );
//查询代金券批次
$ result = $ wp -> queryCouponStock ( $ coupon_stock_id );