php實現微信和支付寶支付

2021-10-09 01:51:48 字數 2006 閱讀 5679

這裡我是在yii框架實現的,安裝easywechat外掛程式

composer require jianyan74/yii2-easy-wechat
一:配置easywechat

1:在config/main.php 的 component中新增easywechat的sdk

'components' => [

// ...

'wechat' => [

'class' => 'jianyan\easywechat\wechat',

'useroptions' => ,  // 使用者身份類引數

'returnurlparam' => '_wechatreturnurl', // returnurl 儲存在會話中

'rebinds' => [ // 自定義服務模組 

// 'cache' => 'common\components\cache',]],

// ...

]

'wechatconfig' => ,

'wechatpaymentconfig' => ,

'wechatminiprogramconfig' => ,

'wechatopenplatformconfig' => ,

'wechatworkconfig' => ,

'wechatopenworkconfig' => ,

'wechatmicromerchantconfig' => ,

具體配置方法可以參考github的說明:

$data = [

'body' => '',//支付描述

'out_trade_no' => '',//訂單號

'total_fee' => '',//支付金額

'trade_type' => 'jsapi',//支付方式

'openid' => '',//使用者openid

];// 生成支付配置

$result = $payment->order->unify($data);

if ($result['return_code'] == 'success') else   

return $this->render('wxpay', [

'config' => $config

]);

2:在wxpay.php檔案中發起支付

wx.config(<?php echo $jssdk->buildconfig(array('choosewxpay'), true) ?>);

function onbridgeready(),

cancel: function(r) ,

});}

if (typeof weixinjsbridge == "undefined")else if (document.attachevent)

}else

$response = $payment->handlepaidnotify(function($message, $fail) );

$response->send();

php實現支付寶支付

一:在php中安裝支付寶外掛程式

composer require alipaysdk/easysdk

二:php實現支付寶支付

1:配置支付寶

/**

* 支付寶配置

*/public static function getoptions()

2:實現支付寶支付

//載入支付寶配置

factory::setoptions(self::getoptions());

try else

} catch (\exception $e)

根據如上就可以實現支付寶支付

微信支付和支付寶支付

一 先copy下寫給後台的文件 支付寶 互動流程詳見 客戶端 android 呼叫的快捷支付介面如下 該介面需要傳入兩個引數 第二個引數 isshowpayloading 是ui方面的設定,與後台無關。第乙個引數 orderinfo 需要 後台伺服器給出 客戶端發起支付請求需要之前 需要 商戶伺服器...

微信支付 支付寶支付

二 移動端支付寶支付 weixinpay data else if document.attachevent else onbridgeready function res vm.number null vm.router.go 1 vm.base url index.html depositres...

微信支付寶支付

備忘,如果有看到的小夥伴,希望能幫助到你 測試的時候一定要用自定義基座測試 證書檔案是你的.keystore檔案路徑,在生成證書的時候一點更要記住檔案位置和密碼!實在忘記了,就最簡單粗暴的方法,重新生成把,但是在重新生成時,一定要記得把相關用到證書資訊的地方全部修改一遍。cmd開啟 生成.keyst...