mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-09-11 06:39:46 +08:00
[更新]增加微信扫码支付测试
This commit is contained in:
parent
3083433222
commit
7dbf23b444
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
namespace app\store\controller\wechat;
|
namespace app\store\controller\wechat;
|
||||||
|
|
||||||
|
use Endroid\QrCode\QrCode;
|
||||||
use service\WechatService;
|
use service\WechatService;
|
||||||
use WeChat\Pay;
|
use WeChat\Pay;
|
||||||
|
|
||||||
@ -24,6 +25,45 @@ use WeChat\Pay;
|
|||||||
*/
|
*/
|
||||||
class Demo
|
class Demo
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫码支付测试
|
||||||
|
* @return \think\Response
|
||||||
|
* @throws \Endroid\QrCode\Exceptions\ImageFunctionFailedException
|
||||||
|
* @throws \Endroid\QrCode\Exceptions\ImageFunctionUnknownException
|
||||||
|
* @throws \Endroid\QrCode\Exceptions\ImageTypeInvalidException
|
||||||
|
* @throws \WeChat\Exceptions\InvalidResponseException
|
||||||
|
*/
|
||||||
|
public function scan()
|
||||||
|
{
|
||||||
|
$wechat = new Pay(config('wechat.'));
|
||||||
|
$options = [
|
||||||
|
'body' => '测试商品',
|
||||||
|
'out_trade_no' => time(),
|
||||||
|
'total_fee' => '1',
|
||||||
|
'trade_type' => 'NATIVE',
|
||||||
|
'notify_url' => url('@wx-demo-notify', '', true, true),
|
||||||
|
'spbill_create_ip' => request()->ip(),
|
||||||
|
];
|
||||||
|
// 生成预支付码
|
||||||
|
$result = $wechat->createOrder($options);
|
||||||
|
return $this->createQrc($result['code_url']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公众号JSAPI支付二维码
|
||||||
|
* @return \think\Response
|
||||||
|
* @throws \Endroid\QrCode\Exceptions\ImageFunctionFailedException
|
||||||
|
* @throws \Endroid\QrCode\Exceptions\ImageFunctionUnknownException
|
||||||
|
* @throws \Endroid\QrCode\Exceptions\ImageTypeInvalidException
|
||||||
|
*/
|
||||||
|
public function jsapiQrc()
|
||||||
|
{
|
||||||
|
$url = url('@wx-demo-jsapi', '', true, true);
|
||||||
|
return $this->createQrc($url);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 公众号JSAPI支付测试
|
* 公众号JSAPI支付测试
|
||||||
* @link wx-demo-jsapi
|
* @link wx-demo-jsapi
|
||||||
@ -43,7 +83,7 @@ class Demo
|
|||||||
'openid' => $openid,
|
'openid' => $openid,
|
||||||
'trade_type' => 'JSAPI',
|
'trade_type' => 'JSAPI',
|
||||||
'notify_url' => url('@wx-demo-notify', '', true, true),
|
'notify_url' => url('@wx-demo-notify', '', true, true),
|
||||||
'spbill_create_ip' => '127.0.0.1',
|
'spbill_create_ip' => request()->ip(),
|
||||||
];
|
];
|
||||||
// 生成预支付码
|
// 生成预支付码
|
||||||
$result = $wechat->createOrder($options);
|
$result = $wechat->createOrder($options);
|
||||||
@ -90,4 +130,19 @@ class Demo
|
|||||||
return 'SUCCESS';
|
return 'SUCCESS';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示二维码
|
||||||
|
* @param string $url
|
||||||
|
* @return \think\Response
|
||||||
|
* @throws \Endroid\QrCode\Exceptions\ImageFunctionFailedException
|
||||||
|
* @throws \Endroid\QrCode\Exceptions\ImageFunctionUnknownException
|
||||||
|
* @throws \Endroid\QrCode\Exceptions\ImageTypeInvalidException
|
||||||
|
*/
|
||||||
|
protected function createQrc($url)
|
||||||
|
{
|
||||||
|
$qrCode = new QrCode();
|
||||||
|
$qrCode->setText($url)->setSize(300)->setPadding(20)->setImageType(QrCode::IMAGE_TYPE_PNG);
|
||||||
|
return \think\facade\Response::header('Content-Type', 'image/png')->data($qrCode->get());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -33,10 +33,18 @@
|
|||||||
<img class="notselect" data-tips-image src="{:url('@wechat/api.tools/oauth_qrc')}" style="width:80px;margin-left:-4px">
|
<img class="notselect" data-tips-image src="{:url('@wechat/api.tools/oauth_qrc')}" style="width:80px;margin-left:-4px">
|
||||||
<p class="text-center" style="margin-left:-10px">网页授权</p>
|
<p class="text-center" style="margin-left:-10px">网页授权</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="pull-left padding-left-0">
|
<div class="pull-left padding-left-0 padding-right-15">
|
||||||
<img class="notselect" data-tips-image src="{:url('@wechat/api.tools/jssdk_qrc')}" style="width:80px;">
|
<img class="notselect" data-tips-image src="{:url('@wechat/api.tools/jssdk_qrc')}" style="width:80px;">
|
||||||
<p class="text-center">JSSDK签名</p>
|
<p class="text-center">JSSDK签名</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="pull-left padding-left-0 padding-right-15">
|
||||||
|
<img class="notselect" data-tips-image src="{:url('@wx-demo-jsapiqrc')}" style="width:80px;">
|
||||||
|
<p class="text-center">JSAPI支付</p>
|
||||||
|
</div>
|
||||||
|
<div class="pull-left padding-left-0">
|
||||||
|
<img class="notselect" data-tips-image src="{:url('@wx-demo-scan')}" style="width:80px;">
|
||||||
|
<p class="text-center">扫码2支付</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user