Browse Source

test

master
用户名 3 years ago
parent
commit
1e26b4367b
  1. 67
      mobile/blank.php
  2. 85
      mobile/plugins/payment/wxpay.php

67
mobile/blank.php

@ -0,0 +1,67 @@
<?php
// 获取上一个页面的 URL
$referer = $_SERVER['HTTP_REFERER'];
$appid = 'wx79343915f99167e6';
$appsecret = 'f2f72c5e0ac29c2373bfaf22cf059c02';
$redirect_uri = 'https://shop.heavenk.com/mobile/blank.php'; // 回调URL
// 构造授权链接
$auth_url = 'https://open.weixin.qq.com/connect/oauth2/authorize'
. '?appid=' . urlencode($appid)
. '&redirect_uri=' . urlencode($redirect_uri)
. '&response_type=code'
. '&scope=snsapi_userinfo' // snsapi_base 只获取openid,snsapi_userinfo 获取用户信息
. '&state=STATE'; // wechat_redirect
// 如果用户已经授权,则重定向到回调URL,并获取用户的openid
if (isset($_GET['code'])) {
$code = $_GET['code'];
// 构造获取access_token的URL
$token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token'
. '?appid=' . urlencode($appid)
. '&secret=' . urlencode($appsecret)
. '&code=' . urlencode($code)
. '&grant_type=authorization_code';
// 发送HTTP请求获取access_token
// 创建一个cURL句柄
$ch = curl_init();
// 设置请求的URL和其他选项
curl_setopt($ch, CURLOPT_URL, $token_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 发送HTTP GET请求并获取响应
$response = curl_exec($ch);
// 检查是否有错误发生
if(curl_errno($ch)) {
echo 'cURL Error: ' . curl_error($ch);
}
// 关闭cURL句柄
curl_close($ch);
// 输出响应
$response = json_decode($response);
var_dump($response->openid);
$_SESSION['openid'] = $response->openid;
// return $response->openid;
// 跳回原来的页面
$redirect_url = $referer;
header("Location: $redirect_url");
exit;
} else {
// 如果没有授权,则重定向到授权页面
header('Location: ' . $auth_url);
var_dump($_GET['code']);
exit();
}
?>

85
mobile/plugins/payment/wxpay.php

@ -112,7 +112,7 @@ class wxpay
{ {
$appid = 'wx79343915f99167e6'; $appid = 'wx79343915f99167e6';
$appsecret = 'f2f72c5e0ac29c2373bfaf22cf059c02'; $appsecret = 'f2f72c5e0ac29c2373bfaf22cf059c02';
$redirect_uri = 'https://shop.heavenk.com/mobile/plugins/payment/wxpay.php'; // 回调URL $redirect_uri = 'https://shop.heavenk.com/mobile/blank.php'; // 回调URL
// 构造授权链接 // 构造授权链接
$auth_url = 'https://open.weixin.qq.com/connect/oauth2/authorize' $auth_url = 'https://open.weixin.qq.com/connect/oauth2/authorize'
@ -188,6 +188,8 @@ class wxpay
// return false; // return false;
// $openid = $this->get_openid(); // $openid = $this->get_openid();
header('Location: https://shop.heavenk.com/mobile/blank.php');
exit; // 终止当前脚本的执行,确保页面跳转生效
// $_SESSION['openid'] = $openid; // $_SESSION['openid'] = $openid;
} }
@ -201,46 +203,46 @@ class wxpay
$this->setParameter("notify_url", __URL__ . 'wxpay.php'); // 通知地址 $this->setParameter("notify_url", __URL__ . 'wxpay.php'); // 通知地址
$this->setParameter("trade_type", "JSAPI"); // 交易类型 $this->setParameter("trade_type", "JSAPI"); // 交易类型
// $prepay_id = $this->getPrepayId(); $prepay_id = $this->getPrepayId();
// $jsApiParameters = $this->getParameters($prepay_id); $jsApiParameters = $this->getParameters($prepay_id);
// wxjsbridge // wxjsbridge
// $js = ' $js = '
// <script language="javascript"> <script language="javascript">
// function jsApiCall(){ function jsApiCall(){
// WeixinJSBridge.invoke("getBrandWCPayRequest", WeixinJSBridge.invoke("getBrandWCPayRequest",
// ' . $jsApiParameters . ', ' . $jsApiParameters . ',
// function(res){ function(res){
// if(res.err_msg == "get_brand_wcpay_request:ok") if(res.err_msg == "get_brand_wcpay_request:ok")
// { {
// location.href="' . return_url(basename(__FILE__, '.php')) . '" location.href="' . return_url(basename(__FILE__, '.php')) . '"
// }else }else
// { {
// } }
// } }
// ) )
// }; };
// function callpay() function callpay()
// { {
// if (typeof WeixinJSBridge == "undefined") if (typeof WeixinJSBridge == "undefined")
// { {
// if( document.addEventListener ) if( document.addEventListener )
// { {
// document.addEventListener("WeixinJSBridgeReady", jsApiCall, false); document.addEventListener("WeixinJSBridgeReady", jsApiCall, false);
// }else if (document.attachEvent) }else if (document.attachEvent)
// { {
// document.attachEvent("WeixinJSBridgeReady", jsApiCall); document.attachEvent("WeixinJSBridgeReady", jsApiCall);
// document.attachEvent("onWeixinJSBridgeReady", jsApiCall); document.attachEvent("onWeixinJSBridgeReady", jsApiCall);
// } }
// }else }else
// { {
// jsApiCall(); jsApiCall();
// } }
// } }
// </script>'; </script>';
// $button = '<a class="box-flex btn-submit" type="button" onclick="callpay()">微信支付(测试)</a>' . $js; $button = '<a class="box-flex btn-submit" type="button" onclick="callpay()">微信支付(测试)</a>' . $js;
$button = '<a class="box-flex btn-submit" type="button" onclick="">微信支付(测试)</a>'; // $button = '<a class="box-flex btn-submit" type="button" onclick="">微信支付(测试)</a>';
return $button; return $button;
@ -452,7 +454,8 @@ class wxpay
function getPrepayId() function getPrepayId()
{ {
// 设置接口链接 // 设置接口链接
$url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; // $url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
$url = "https://epay.dalianpay.cn/payapi/unitorder/pay";
try { try {
// 检测必填参数 // 检测必填参数
if ($this->parameters["out_trade_no"] == null) { if ($this->parameters["out_trade_no"] == null) {

Loading…
Cancel
Save