Browse Source

测试判断微信支付方式

master
lixiaoyu 3 years ago
parent
commit
a6da64df75
  1. 61
      mobile/blankmini.php
  2. 1
      mobile/source/apps/flow/controllers/IndexController.php
  3. 3
      mobile/source/apps/flow/views/done.html

61
mobile/blankmini.php

@ -0,0 +1,61 @@
<?php
// 获取上一个页面的 URL
session_start();
$referer = $_SESSION['prev_url'];
// unset($_SESSION['prev_url']);
$appid = 'wx1663d2c6a7937c78';
$appsecret = '979d165d51759c3f1fbb357747b3311d';
$redirect_uri = 'https://shop.heavenk.com/mobile/blank.php'; // 回调URL
$template_id = '5JCt5gNGM7sfwWnRqwWsjH138DixCFJ7sPEbToYQAmQ';
// 获取授权 code
if (!isset($_GET['code'])) {
$url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $appid . '&redirect_uri=' . urlencode($redirect_uri) . '&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
header('Location: ' . $url);
exit;
}
// 获取 access_token 和 openid
$code = $_GET['code'];
if ($code != null){
// var_dump($code);
} else {
var_dump("code is null");
} // code已经成功获取到
$url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $appsecret . '&code=' . $code . '&grant_type=authorization_code';
$response = file_get_contents($url);
echo $response;
$data = json_decode($response, true);
echo $data;
if (!$data || !isset($data['access_token']) || !isset($data['openid'])) {
// 授权失败
echo '授权失败,请重试';
exit;
}
// 获取用户信息
$access_token = $data['access_token'];
$openid = $data['openid'];
$url = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $access_token . '&openid=' . $openid . '&lang=zh_CN';
$response = file_get_contents($url);
$userinfo = json_decode($response, true);
if (!$userinfo || !isset($userinfo['openid'])) {
// 获取用户信息失败
echo '获取用户信息失败,请重试';
exit;
}
$_SESSION['openid'] = $openid;
$_SESSION['access_token'] = $$access_token;
// echo $openid;
header('Location: ' . $referer);
exit;
// 用户授权成功,这里可以将用户信息保存到数据库中,或者进行其他操作
// var_dump($userinfo);
?>

1
mobile/source/apps/flow/controllers/IndexController.php

@ -526,7 +526,6 @@ class IndexController extends FrontendController {
* 订单提交 * 订单提交
*/ */
public function actiondone(){ public function actiondone(){
var_dump("==================");
/* 取得购物类型 */ /* 取得购物类型 */
$flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS; $flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;

3
mobile/source/apps/flow/views/done.html

@ -1,8 +1,8 @@
{include file="page_header"} {include file="page_header"}
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
<div class="con"> <div class="con">
<div class="flow-done"> <div class="flow-done">
<div class="flow-done-con"> <div class="flow-done-con">
{$order.pay_code}
{if $order.pay_code == 'balance'} {if $order.pay_code == 'balance'}
<i class="iconfont icon-hookring2"></i> <i class="iconfont icon-hookring2"></i>
<p class="flow-done-title">余额支付成功</p> <p class="flow-done-title">余额支付成功</p>
@ -16,6 +16,7 @@
{/if} {/if}
{/if} {/if}
</div> </div>
{$child_order}
{if $child_order > 1} {if $child_order > 1}
<div class="flow-done-all"> <div class="flow-done-all">
{foreach $child_order_info as $child} {foreach $child_order_info as $child}

Loading…
Cancel
Save