中国建设银采购发文网站,电商网站搜索引擎怎么做,购物网站二级页面模板,怎么做广告宣传最有效微信扫码支付#xff08;laravel#xff09;
1.未开通微信扫码支付
(1).参照微信扫码支付接入步骤
(2).开通成功之后用分配的商户号登录微信商户平台设置扫码支付的异步回调地址#xff08;注意#xff1a;是返给商户后台的回调地址#xff09;
2.已经开通扫码支付
模…微信扫码支付laravel
1.未开通微信扫码支付
(1).参照微信扫码支付接入步骤
(2).开通成功之后用分配的商户号登录微信商户平台设置扫码支付的异步回调地址注意是返给商户后台的回调地址
2.已经开通扫码支付
模式二
业务流程参照微信支付文档模式二
代码贴上 ?php
namespace App\Http\Controllers\Dsp;use App\DspAccount;
use App\DspUser;
use App\StarShow\AliPay;
use App\StarShow\Qrcode;
use App\StarShow\WechatPay;
use Illuminate\Http\Request;
use Log;
use StarShowResponse;
use Validator;class AccountController extends Controller {protected $alipay;protected $wechat;protected $qrcode;public function __construct(AliPay $alipay, WechatPay $wechat, Qrcode $qrcode) {$this-alipay $alipay;$this-wechat $wechat;$this-qrcode $qrcode;}//dsp项目充值public function recharge(Request $request, $user_id) {$validator Validator::make($request-all(), [total_amount required,payment_type required,]);if ($validator-fails()) {return StarShowResponse::response($validator-errors()-first(), 422);}//$user_id $request-input(user_id);$total_amount $request-input(total_amount);$payment_type $request-input(payment_type);//账户余额$account_balance DspUser::find($user_id)-account;//-select(select * from users where user_id . $user_id);$out_trade_no date(YmdHis) . rand(0, 9);$account DspAccount::create([user_id $user_id,payment_type $payment_type,account_balance $account_balance,name DSP账户充值,out_trade_no $out_trade_no,total_amount $total_amount,]);switch ($payment_type) {case 1: //微信$params array(appid config(wechat.app_id),mch_id config(wechat.mch_id),nonce_str str_random(16),body 时尚星秀-DSP充值,out_trade_no $out_trade_no,total_fee $total_amount * 100, //微信支付单位为分time_start date(YmdHis),time_expire date(YmdHis, time() 300),spbill_create_ip $_SERVER[SERVER_ADDR],notify_url config(weixin.dsp_notify_url),trade_type NATIVE,product_id $out_trade_no,);Log::info(订单失效时间 . $params[time_expire]);$params[sign] $this-wechat-getSign($params, true);$rst $this-wechat-curl_post_ssl(https://api.mch.weixin.qq.com/pay/unifiedorder, $this-wechat-arrayToXml($params));$result $this-wechat-xmlToArray($rst);if (array_key_exists(return_code, $result) array_key_exists(result_code, $result) $result[return_code] SUCCESS $result[result_code] SUCCESS) {$url $result[code_url];$code_url $this-qrcode-generate($url);Log::info(二维码 . env(APP_HOST) . $code_url);$data [code_url env(APP_HOST) . $code_url,out_trade_no $out_trade_no,time_expire date(Y-m-d H:i:s, strtotime($params[time_expire])),];return StarShowResponse::response($data, 200);} else {return StarShowResponse::response($result[return_msg], 500);}break;case 2: //支付宝$res $this-alipay-tradePagePay($out_trade_no, $total_amount);return $res;break;}}
}
Alipay.php ?php
namespace App\StarShow;
header(Content-type:text/html;charsetutf-8);
require_once AliSign/AopSdk.php;
require_once AliSign/service/AlipayTradeService.php;
require_once AliSign/buildermodel/AlipayTradePagePayContentBuilder.php;
/**
* alipay pay class
*/
class AliPay {
public $private_key ;
public $alipay_public_key ;
//签名方式
public $signtype RSA;
//电脑网页支付
public function tradePagePay($out_trade_no, $total_amount) {
//支付宝配置
$config config(latrell-alipay-web);
$config[private_key] $this-private_key;
$config[alipay_public_key] $this-alipay_public_key;
//构造参数
$payRequestBuilder new \AlipayTradePagePayContentBuilder();
//商品描述可空
$payRequestBuilder-setBody(充值);
//订单名称必填
$payRequestBuilder-setSubject(账户充值);
$payRequestBuilder-setTotalAmount($total_amount);
$payRequestBuilder-setOutTradeNo($out_trade_no);
$aop new \AlipayTradeService($config);
$response $aop-pagePay($payRequestBuilder, $config[return_url], $config[notify_url]);
// 跳转到支付页面。
return $response;
}
}phpqrcode.php 文件在下载的微信支付demo里面就有
贴上二维码图片文件生成代码 ?php
namespace App\StarShow;
require_once Phpqrcode/phpqrcode.php;/****/
class Qrcode {public function generate($text) {error_reporting(E_ERROR);$url urldecode($text);$PNG_TEMP_DIR getcwd() . /temp/;if (!file_exists($PNG_TEMP_DIR)) {mkdir($PNG_TEMP_DIR);}$filename test . md5($url . |L|4) . .png;\QRcode::png($url, $PNG_TEMP_DIR . $filename, L, 4, 2);return /temp/ . $filename;}
}本人遇到的问题是选择微信支付之后直接生成了二维码扫码之后没有任何反应故改变二维码的生成策略选择支付方式为微信支付之后点击去支付此时后台生成一个二维码图片订单号订单失效时间服务器当前时间一起返给前端这个时候前端做的处理是遮罩层弹出二维码从弹出二维码那一刻前端根据订单失效时间服务器当前时间时间差 用这个时间差做一个2-3s定时请求后台的处理根据订单号来定时请求后台查看支付结果在失效时间结束之前如果支付成功则做各自的业务处理如果失败则继续请求直到失效时间结束如果用户关闭页面则不在验证。
有问题可以联系qq:1275920140