Browse Source

update wxpay

master
用户名 3 years ago
parent
commit
ae9349d057
  1. 62
      mobile/plugins/payment/wxpay.php

62
mobile/plugins/payment/wxpay.php

@ -106,30 +106,13 @@ class wxpay
}
/**
* 生成支付代码
* @param array $order 订单信息
* @param array $payment 支付方式信息
* 获取openid
*/
public function get_code($order, $payment)
public function get_openid()
{
include_once(BASE_PATH.'helpers/payment_helper.php');
// 配置参数
$this->payment = $payment;
// 网页授权获取用户openid
if (! isset($_SESSION['openid']) || empty($_SESSION['openid'])) {
// $button = '<a class="box-flex btn-submit" type="button" onclick="">微信支付</a>';
// return $button;
// 应该重新发起授权登录
// require_once("../connect/wechat.php");
// return wxchat::redirect("shop/mobile");
// $_SESSION['openid'] = 'sdf4asgdf2ag1';
// return false;
// 设置应用信息
$appid = 'wx79343915f99167e6';
$appsecret = 'f2f72c5e0ac29c2373bfaf22cf059c02';
$redirect_uri = 'https://shop.heavenk.com/mobile/plugins/payment/wxpay.php'; // 回调URL
$redirect_uri = 'https://shop.heavenk.com/mobile/source/apps/flow/views/done.html'; // 回调URL
// 构造授权链接
$auth_url = 'https://open.weixin.qq.com/connect/oauth2/authorize'
@ -143,8 +126,6 @@ class wxpay
if (isset($_GET['code'])) {
$code = $_GET['code'];
// $code = '100010';
// 构造获取access_token的URL
$token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token'
. '?appid=' . urlencode($appid)
@ -174,17 +155,9 @@ class wxpay
// 输出响应
$response = json_decode($response);
// var_dump($response->openid);
$_SESSION['openid'] = $response->openid;
var_dump($response->openid);
return $response->openid;
// $client = new \GuzzleHttp\Client();
// $response = $client->request('GET', $token_url);
// $result = json_decode($response->getBody(), true);
// $openid = $result['openid'];
// // 在这里处理获取到的openid
// echo $openid;
} else {
// 如果没有授权,则重定向到授权页面
header('Location: ' . $auth_url);
@ -193,6 +166,31 @@ class wxpay
}
}
/**
* 生成支付代码
* @param array $order 订单信息
* @param array $payment 支付方式信息
*/
public function get_code($order, $payment)
{
include_once(BASE_PATH.'helpers/payment_helper.php');
// 配置参数
$this->payment = $payment;
// 网页授权获取用户openid
if (! isset($_SESSION['openid']) || empty($_SESSION['openid'])) {
// $button = '<a class="box-flex btn-submit" type="button" onclick="">微信支付</a>';
// return $button;
// 应该重新发起授权登录
// require_once("../connect/wechat.php");
// return wxchat::redirect("shop/mobile");
// $_SESSION['openid'] = 'sdf4asgdf2ag1';
// return false;
$openid = $this->get_openid();
$_SESSION['openid'] = $openid;
}
// 设置必填参数
// 根目录url
$order_amount = $order['order_amount'] * 100;

Loading…
Cancel
Save