Skip to content

Commit

Permalink
增加微信小程序支付功能和微信app内支付功能
Browse files Browse the repository at this point in the history
  • Loading branch information
brjunsuc committed Mar 3, 2023
1 parent 5a7ed22 commit 69f0d56
Show file tree
Hide file tree
Showing 23 changed files with 269 additions and 797 deletions.
9 changes: 7 additions & 2 deletions addons/demo_rgapi/demo_rgapi_wxapp/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"pages": [
"demo_rgapi/pages/index/index",
"demo_rgapi/pages/add/add",
"demo_rgapi/pages/edit/edit"
"demo_rgapi/pages/edit/edit",
"demo_rgapi/pages/pay/index"
],
"window": {
"navigationBarTextStyle": "white",
Expand All @@ -20,7 +21,11 @@
{
"pagePath": "demo_rgapi/pages/add/add",
"text": "新增"
},
{
"pagePath": "demo_rgapi/pages/pay/index",
"text": "支付"
}
]
}
}
}
73 changes: 73 additions & 0 deletions addons/demo_rgapi/demo_rgapi_wxapp/demo_rgapi/pages/pay/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import http from '../../util/request.js';
import pay from '../../util/pay.js';

// demo_rgapi/pages/pay/index.js
Page({

/**
* 页面的初始数据
*/
data: {

},

/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {

},

/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {

},

/**
* 生命周期函数--监听页面显示
*/
onShow() {

},

/**
* 生命周期函数--监听页面隐藏
*/
onHide() {

},

/**
* 生命周期函数--监听页面卸载
*/
onUnload() {

},

pay: function(e) {
pay('orderid');
},

/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {

},

/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {

},

/**
* 用户点击右上角分享
*/
onShareAppMessage() {

}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"usingComponents": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!--demo_rgapi/pages/pay/index.wxml-->
<text>小程序支付:</text>
<view class="weui-btn-area">
<button class="weui-btn" type="primary" bindtap="pay">去支付</button>
</view>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* demo_rgapi/pages/pay/index.wxss */
4 changes: 2 additions & 2 deletions addons/demo_rgapi/demo_rgapi_wxapp/demo_rgapi/util/pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ function wxPay(param) {
console.log('wxPay');
return new Promise((resolve, reject)=>{
wx.requestPayment({
'timeStamp': param.timeStamp,
'timeStamp': param.timeStamp.toString(),
'nonceStr': param.nonceStr,
'package': param.package,
'signType': 'MD5',
'signType': param.signType,
'paySign': param.paySign,
'success': function (res) {
console.log(res);
Expand Down
4 changes: 2 additions & 2 deletions addons/demo_rgapi/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`no` varchar(255) NOT NULL DEFAULT '' COMMENT '商户订单号',
`code` varchar(255) NOT NULL DEFAULT '' COMMENT '二维码链接',
`status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '状态',
`type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '支付类型 1:微信;2:支付宝;',
`status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '状态 0:未支付;1:已支付;2:已退款;',
`type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '支付类型 1:Native(微信扫码);2:ali(支付宝);3:Wechat(公众号jsapi);4:Wxapp(小程序jsapi);',
`createtime` int(11) NOT NULL COMMENT '创建时间',
`updatetime` int(11) NOT NULL DEFAULT 0 COMMENT '更新时间',
`uid` varchar(255) NOT NULL DEFAULT '' COMMENT '用户标识',
Expand Down
2 changes: 1 addition & 1 deletion addons/demo_rgapi/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<application setting="false">
<name><![CDATA[软擎授权示例应用]]></name>
<identifie><![CDATA[demo_rgapi]]></identifie>
<version><![CDATA[1.0.0]]></version>
<version><![CDATA[1.0.1]]></version>
<type><![CDATA[activity]]></type>
<ability><![CDATA[基于软擎授权系统的独立系统示例应用。]]></ability>
<description><![CDATA[基于软擎授权系统的独立系统示例应用,供开发者参考]]></description>
Expand Down
48 changes: 38 additions & 10 deletions addons/demo_rgapi/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ public function doMobileIndex() {
global $_W;
include $this->template('index');
}

public function doMobilePay() {
global $_W, $_GPC;
$out_trade_no = 'wechat' . date('YmdHis', time()) . time() . rand(11, 99);

$insert = array(
'no' => $out_trade_no,
'code' => '',
'status' => 0,
'type' => 3,
'createtime' => TIMESTAMP,
'updatetime' => TIMESTAMP,
'uid' => $_W['uid'],
'uniacid' => $_W['uniacid'],
);
pdo_insert('demo_rgapi_paylog', $insert);

$params['tid'] = $out_trade_no;
$params['ordersn'] = $out_trade_no;
$params['user'] = $_W['uid'];
$params['fee'] = 0.01;
$params['title'] = '测试支付';
$this->pay($params);
}

public function doWebList() {
global $_W, $_GPC;
$data = pdo_getall(self::TABLE, array(), '', 'orderBy createtime desc');
Expand Down Expand Up @@ -46,7 +71,7 @@ public function doWebOther() {

public function doWebWechatpay() {
global $_W;
$data = pdo_getall('demo_rgapi_paylog', array('type' => 1), '', '', 'id DESC');
$data = pdo_getall('demo_rgapi_paylog', array('type in' => array(1, 3, 4)), '', '', 'id DESC');
foreach ($data as $key => &$value) {
$value['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
}
Expand All @@ -70,18 +95,19 @@ public function doWebPay() {
iajax(-1, '支付类型错误!');
}
load()->library('sdk-module');
$api = new \W7\Sdk\Module\Api($_W['setting']['server_setting']['app_id'], $_W['setting']['server_setting']['app_secret'], "1");
$api = new \W7\Sdk\Module\Api($_W['setting']['server_setting']['app_id'], $_W['setting']['server_setting']['app_secret'], "1", V3_API_DOMAIN);
$uniontid = date('YmdHis') . random(14, 1);
$out_trade_no = $type . date('YmdHis', time()) . time() . rand(11, 99);
if ('wechat' == $type) {
$pay = $api->wechatPay($_W['siteroot'] . 'payment/wechat/notify.php');
$data = $pay->payTransactionsNative("测试支付", $out_trade_no, 1, array('attach' => json_encode(array('uniacid' => $_W['uniacid']))))->toArray();
$data = $pay->payTransactionsNative("测试支付", $uniontid, 1, array('attach' => json_encode(array('uniacid' => $_W['uniacid']))))->toArray();
if (empty($data['code_url'])) {
iajax(-1, '支付失败!');
}
$code = $data['code_url'];
} else {
$pay = $api->aliPay($_W['siteroot'] . 'payment/alipay/notify.php');
$data = $pay->payForPc("测试支付", $out_trade_no, 0.01)->toArray();
$data = $pay->payForPc("测试支付", $uniontid, 0.01)->toArray();
if (empty($data['data'])) {
iajax(-1, '支付失败!');
}
Expand All @@ -94,7 +120,7 @@ public function doWebPay() {
'acid' => $_W['acid'],
'openid' => $_W['member']['uid'],
'module' => 'demo_rgapi',
'uniontid' => $out_trade_no,
'uniontid' => $uniontid,
'tid' => $out_trade_no,
'fee' => 0.01,
'card_fee' => 0.01,
Expand Down Expand Up @@ -127,17 +153,19 @@ public function doWebRefund() {
iajax(-1, '退款类型错误!');
}
load()->library('sdk-module');
$api = new \W7\Sdk\Module\Api($_W['setting']['server_setting']['app_id'], $_W['setting']['server_setting']['app_secret'], "1");
$out_trade_no = safe_gpc_string($_GPC['__input']['no']);
$paylog = pdo_get('core_paylog', array('tid' => $out_trade_no));
$account_type = 'wxapp' == $paylog['type'] ? 2 : 1;
$api = new \W7\Sdk\Module\Api($_W['setting']['server_setting']['app_id'], $_W['setting']['server_setting']['app_secret'], $account_type, V3_API_DOMAIN);
if ('wechat' == $type) {
$pay = $api->wechatPay($_W['siteroot'] . 'payment/wechat/refund.php');
$data = $pay->refund($out_trade_no, 1, 1, '', $out_trade_no)->toArray();
$data = $pay->refund($out_trade_no, 1, 1, '', $paylog['uniontid'])->toArray();
if (!empty($data['status']) && 'SUCCESS' == $data['status']) {
iajax(0, '已申请退款!');
}
} else {
$pay = $api->aliPay($_W['siteroot'] . 'payment/alipay/refund.php');
$data = $pay->refund($out_trade_no, 0.01)->toArray();
$data = $pay->refund($paylog['uniontid'], 0.01)->toArray();
}
$refund = array(
'uniacid' => $_W['uniacid'],
Expand All @@ -162,15 +190,15 @@ public function doWebRefund() {
public function payResult($params) {
$paylog = pdo_get('core_paylog', array('uniontid' => $params['uniontid']));
if (!empty($paylog['status'])) {
pdo_update('demo_rgapi_paylog', array('status' => 1), array('no' => $params['uniontid']));
pdo_update('demo_rgapi_paylog', array('status' => 1), array('no' => $paylog['tid']));
}
exit('success');
}

public function refundResult($params) {
$paylog = pdo_get('core_refundlog', array('refund_uniontid' => $params['refund_uniontid']));
if (!empty($paylog['status'])) {
pdo_update('demo_rgapi_paylog', array('status' => 2), array('no' => $params['uniontid']));
pdo_update('demo_rgapi_paylog', array('status' => 2), array('no' => $paylog['uniontid']));
}
exit('success');
}
Expand Down
6 changes: 6 additions & 0 deletions addons/demo_rgapi/template/mobile/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@
<p>{$_W['openid']}</p>
</div>
</div>
<div class="mui-table mui-table-inline mui-mt15 nav-action">
<div class="mui-table-cell">
微信支付:
<p><a href="{php echo $this->createMobileUrl('pay')}" type="button" class="btn btn-default" style="line-height: 24px;">去支付</a></p>
</div>
</div>
</div>
{template 'common/footer'}
10 changes: 9 additions & 1 deletion addons/demo_rgapi/template/wechatpay.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
<col width="250px"/>
<col width="250px" />
<col width="100px" />
<col width="100px" />
<col width="50px" />
<tr>
<th>订单号</th>
<th>创建时间</th>
<th>状态</th>
<th>来源</th>
<th class="text-center">操作</th>
</tr>
<tr ng-repeat="item in data">
Expand All @@ -24,11 +26,17 @@
<span ng-if="2 == item.status">已退款</span>
<span ng-if="0 == item.status">未支付</span>
</td>
<td>
<span ng-if="1 == item.type">Native</span>
<span ng-if="3 == item.type">Wechat</span>
<span ng-if="4 == item.type">Wxapp</span>
</td>
<td class="text-center">
<div class="link-group">
<a href="javascript:;" ng-if="1 == item.status" ng-click="refund(item.no)">退款</a>
<a href="javascript:;" ng-if="2 == item.status">-</a>
<a href="javascript:;" ng-if="0 == item.status" ng-click="pay(1, item.code, item.no)">支付</a>
<a href="javascript:;" ng-if="0 == item.status && (3 == item.type || 4 == item.type)">-</a>
<a href="javascript:;" ng-if="0 == item.status && 3 != item.type && 4 != item.type" ng-click="pay(1, item.code, item.no)">支付</a>
</div>
</td>
</tr>
Expand Down
31 changes: 31 additions & 0 deletions addons/demo_rgapi/upgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

$tablename_riji = tablename('demo_rgapi_riji');
$tablename_paylog = tablename('demo_rgapi_paylog');
$sql = <<<EOT
CREATE TABLE IF NOT EXISTS $tablename_riji (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`title` varchar(255) NOT NULL DEFAULT '' COMMENT '日记标题',
`content` varchar(255) NOT NULL DEFAULT '' COMMENT '日记内容',
`createtime` int(11) NOT NULL COMMENT '创建时间',
`updatetime` int(11) NOT NULL COMMENT '更新时间',
`uid` varchar(255) NOT NULL DEFAULT '' COMMENT '用户标识',
`uniacid` int(11) NOT NULL DEFAULT '0',
`image` varchar(255) NOT NULL DEFAULT '' COMMENT '图片路径',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS $tablename_paylog (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`no` varchar(255) NOT NULL DEFAULT '' COMMENT '商户订单号',
`code` varchar(255) NOT NULL DEFAULT '' COMMENT '二维码链接',
`status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '状态',
`type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '支付类型 1:微信;2:支付宝;',
`createtime` int(11) NOT NULL COMMENT '创建时间',
`updatetime` int(11) NOT NULL DEFAULT 0 COMMENT '更新时间',
`uid` varchar(255) NOT NULL DEFAULT '' COMMENT '用户标识',
`uniacid` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
EOT;

pdo_query($sql);
Loading

0 comments on commit 69f0d56

Please sign in to comment.