payment.php
13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
use yii\helpers\Url;
?>
<?=$this->render("_header",['tab' => 'wechat_payment'])?>
<script src="<?= Yii::$app->request->baseUrl . "/exts/base/1.0.0/ui/zclip/zclip.min.js"?>"></script>
<div class="col-md-12" style="padding: 0px;">
<div class="panel panel-default">
<div class="panel-heading">
<b>公众号微信支付设置</b>
</div>
<div class="panel-body">
<table class="table">
<thead>
<tr>
<td>
<p>1. 登录<span class="text-danger">微信公众平台</span>, 进入【微信支付】>【开发配置】, 配置以下信息: <a href="<?=Yii::$app->request->BaseUrl ?>/images/wechatpay-setting-1.png"><查看示例></a></p>
<div>
<div class="col-md-2 text-right" >
<b>支付授权目录</b>
</div>
<div class="col-md-10">
<span class="text-danger"><?=$payment->pay_domain?></span>
<div style="position:relative;display: inline-block">
<a href="javascript:void(0)" class="copy" data-url="<?=$payment->pay_domain?>">复制链接</a>
</div>
<br>
<span class="text-danger"><?=$payment->domain_root?></span>
<div style="position:relative;display: inline-block">
<a href="javascript:void(0)" class="copy" data-url="<?=$payment->domain_root?>">复制链接</a>
</div>
</div>
</div>
</td>
</tr>
</thead>
<tr>
<td>
<p>2. 登录<span class="text-danger">微信公众平台</span>, 进入【微信支付】>【商户信息】, 获取【商户号】并填写保存: <a href="<?=Yii::$app->request->BaseUrl ?>/images/wechatpay-setting-2.png"><查看示例></a></p>
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-md-2 control-label" >
商户号
</label>
<div class="col-md-3">
<input id="mch_id" type="text" class="form-control" placeholder="输入商户号" value="<?=$payment->mch_id?>">
</div>
<div class="col-md-3">
<button id="saveMCH" class="btn btn-primary ladda-button" data-style="slide-up">保存</button>
</div>
</div>
</form>
</td>
</tr>
<tr>
<td>
<p>3. 登录<span class="text-danger">微信支付商户平台</span>, 进入【账号中心】>【API安全】, 获取【API秘钥】并填写保存: <a href="<?=Yii::$app->request->BaseUrl ?>/images/wechatpay-setting-3.png"><查看示例></a></p>
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-md-2 control-label" >
API秘钥
</label>
<div class="col-md-3">
<input id="api_key" type="text" class="form-control" placeholder="输入API秘钥" value="<?=$payment->api_key?>">
</div>
<div class="col-md-3">
<button id="saveApiKey" class="btn btn-primary ladda-button" data-style="slide-up">保存</button>
</div>
</div>
</form>
</td>
</tr>
<tr>
<td>
<p>4. 登录<span class="text-danger">微信支付商户平台</span>, 进入【账号中心】>【API安全】, 下载【API证书】并上传到此处: <a href="<?=Yii::$app->request->BaseUrl ?>/images/wechatpay-setting-3.png"><查看示例></a></p>
<div>
<div class="col-md-2 text-right">
<b>API证书文件</b>
</div>
<div class="col-md-10">
<div class="fileupload" style="display: inline">
<input type="file" name="cert" id="uploadCert" style="width: 120px" />
<a href="javascript:void(0)" class="btn btn-success">
<?php if (!empty($payment->ssl_cert_exists)) : ?>
更新
<?php else : ?>
上传
<?php endif; ?>
</a>
</div>
<br/><br/>
<span class="text-danger">注意: 请上传文件名为apiclient_cert.pem的文件</span>
</div>
<div class="col-md-12" style="padding-top:10px;"></div>
<div class="col-md-2 text-right">
<b>API秘钥文件</b>
</div>
<div class="col-md-10">
<div class="fileupload" style="display: inline">
<input type="file" name="key" id="uploadKey" style="width: 120px" />
<a href="javascript:void(0)" class="btn btn-success">
<?php if (!empty($payment->ssl_key_exists)) : ?>
更新
<?php else : ?>
上传
<?php endif; ?>
</a>
</div>
<br/><br/>
<span class="text-danger">注意: 请上传文件名为apiclient_key.pem的文件</span>
</div>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<script>
(function($, window, document){
$(document).ready(function(){
// 保存商户号
$('#saveMCH').on('click', function(){
// 微信支付商户号
var mch_id = $("#mch_id").val();
var l = $.ladda(this);
$.ajax({
url : '<?= Url::toRoute(['/setting/wechat/payment-save']) ?>',
type : 'post',
dataType : 'json',
data : $.csrf({
mch_id : mch_id,
}),
beforeSend : function(){
l.start();
},
success : function(e){
if (101 == e.code) {
alert('商城不存在, 请重新操作');
}
location.reload();
},
error : function(){},
complete : function(){}
});
});
// 保存API秘钥
$('#saveApiKey').on('click', function(){
// API KEY
var api_key = $("#api_key").val();
var l = $.ladda(this);
$.ajax({
url : '<?= Url::toRoute(['/setting/wechat/payment-save']) ?>',
type : 'post',
dataType : 'json',
data : $.csrf({
api_key : api_key
}),
beforeSend : function(){
l.start();
},
success : function(e){
if (101 == e.code) {
alert('商城不存在, 请重新操作');
}
location.reload();
},
error : function(){},
complete : function(){}
});
});
// 上传apiclient_cert证书文件
$('#uploadCert').change(function() {
seajs.use("base/1.0.0/ui/ajaxfileupload/ajaxfileupload-1.0.0",function () {
$.ajaxFileUpload({
url:'<?=Url::toRoute("/setting/wechat/payment-upload-cert")?>',
secureuri :false,
fileElementId :'uploadCert',//file控件id
dataType : 'json',
type:"post",
success : function (dataResult, status){
if (dataResult.success) {
location.reload();
} else if (dataResult.message) {
alert(dataResult.message)
location.reload();
} else if (dataResult.success == false) {
alert(dataResult.error)
location.reload();
}
},
error: function(data, status, e){
alert("程序发生错误,请联系管理员。")
}
})
})
});
// 上传apiclient_key证书文件
$('#uploadKey').change(function() {
seajs.use("base/1.0.0/ui/ajaxfileupload/ajaxfileupload-1.0.0",function () {
$.ajaxFileUpload({
url:'<?=Url::toRoute("/setting/wechat/payment-upload-key")?>',
secureuri :false,
fileElementId :'uploadKey',//file控件id
dataType : 'json',
type:"post",
success : function (dataResult, status){
if (dataResult.success) {
location.reload();
} else if (dataResult.message) {
alert(dataResult.message)
location.reload();
} else if (dataResult.success == false) {
alert(dataResult.error)
location.reload();
}
},
error: function(data, status, e){
alert("程序发生错误,请联系管理员。")
}
})
})
});
// 上传CA证书
$('#uploadRootca').change(function() {
seajs.use("base/1.0.0/ui/ajaxfileupload/ajaxfileupload-1.0.0",function () {
$.ajaxFileUpload({
url:'<?=Url::toRoute("/setting/wechat/payment-upload-rootca")?>',
secureuri :false,
fileElementId :'uploadRootca',//file控件id
dataType : 'json',
type:"post",
success : function (dataResult, status){
if (dataResult.success) {
location.reload();
} else if (dataResult.message) {
alert(dataResult.message)
location.reload();
} else if (dataResult.success == false) {
alert(dataResult.error)
location.reload();
}
},
error: function(data, status, e){
alert("程序发生错误,请联系管理员。")
}
})
})
});
/* 定义所有class为copy标签,点击后可复制被点击对象的文本 */
$(".copy").zclip({
path: "<?= Yii::$app->request->baseUrl . "/exts/base/1.0.0/ui/zclip/ZeroClipboard.swf" ?>",
copy: function(){
console
return $(this).data('url');
},
beforeCopy:function(){/* 按住鼠标时的操作 */
$(this).css("color","orange");
},
afterCopy:function(){/* 复制成功后的操作 */
var $copysuc = $("<div class='copy-tips'><div class='copy-tips-wrap'>☺ 复制成功</div></div>");
$("body").find(".copy-tips").remove().end().append($copysuc);
$(".copy-tips").fadeOut(3000);
}
});
});
}(jQuery, window, document));
</script>