作者 赵云辉

ios支付修改完成安卓支付注释掉了

@@ -2,8 +2,8 @@ @@ -2,8 +2,8 @@
2 "name" : "问野", 2 "name" : "问野",
3 "appid" : "__UNI__6108A26", 3 "appid" : "__UNI__6108A26",
4 "description" : "问野", 4 "description" : "问野",
5 - "versionName" : "1.6",  
6 - "versionCode" : 109, 5 + "versionName" : "1.4",
  6 + "versionCode" : 112,
7 "transformPx" : false, 7 "transformPx" : false,
8 /* 5+App特有相关 */ 8 /* 5+App特有相关 */
9 "app-plus" : { 9 "app-plus" : {
@@ -97,14 +97,6 @@ @@ -97,14 +97,6 @@
97 } 97 }
98 }, 98 },
99 "payment" : { 99 "payment" : {
100 - "weixin" : {  
101 - "__platform__" : [ "ios", "android" ],  
102 - "appid" : "wx71e7bfe66057f7fb",  
103 - "UniversalLinks" : "https://yuebang.brofirst.cn/ulink/"  
104 - },  
105 - "alipay" : {  
106 - "__platform__" : [ "ios", "android" ]  
107 - },  
108 "appleiap" : {} 100 "appleiap" : {}
109 }, 101 },
110 "geolocation" : { 102 "geolocation" : {
@@ -42,33 +42,38 @@ @@ -42,33 +42,38 @@
42 number: '', //问野币数量 42 number: '', //问野币数量
43 pay_type: 'wechat' 43 pay_type: 'wechat'
44 }, 44 },
  45 + iosPay: {
  46 + order_id: '',
  47 + data: ''
  48 + },
45 showPay: false, //展示支付弹框 49 showPay: false, //展示支付弹框
46 price: 0, 50 price: 0,
47 - list: [{  
48 - num: 10,  
49 - price: 1,  
50 - id: 'S3FKBIR',  
51 - },  
52 - {  
53 - num: 60,  
54 - price: 6,  
55 - id: 'K93MD8T',  
56 - },  
57 - {  
58 - num: 120,  
59 - price: 12,  
60 - id: 'TR5CNJF',  
61 - },  
62 - {  
63 - num: 250,  
64 - price: 25,  
65 - id: 'AIDHZK4',  
66 - },  
67 - {  
68 - num: 500,  
69 - price: 50,  
70 - id: '87FC0DH',  
71 - } 51 + list: [
  52 + // {
  53 + // num: 10,
  54 + // price: 1,
  55 + // id: 'PTMH2SF',
  56 + // },
  57 + // {
  58 + // num: 60,
  59 + // price: 6,
  60 + // id: 'K93MD8T',
  61 + // },
  62 + // {
  63 + // num: 120,
  64 + // price: 12,
  65 + // id: 'TR5CNJF',
  66 + // },
  67 + // {
  68 + // num: 250,
  69 + // price: 25,
  70 + // id: 'AIDHZK4',
  71 + // },
  72 + // {
  73 + // num: 500,
  74 + // price: 50,
  75 + // id: '87FC0DH',
  76 + // }
72 ] 77 ]
73 } 78 }
74 }, 79 },
@@ -76,39 +81,57 @@ @@ -76,39 +81,57 @@
76 payType 81 payType
77 }, 82 },
78 onLoad() { 83 onLoad() {
  84 + this.getMoneyGoods()
79 uni.getProvider({ 85 uni.getProvider({
80 service: 'payment', 86 service: 'payment',
81 success: function(res) { 87 success: function(res) {
82 console.log('获取通道', res.provider) 88 console.log('获取通道', res.provider)
83 } 89 }
84 }); 90 });
85 - 91 +
  92 + let that = this
86 console.log('查看支付通道') 93 console.log('查看支付通道')
87 plus.payment.getChannels((channels) => { 94 plus.payment.getChannels((channels) => {
88 - console.log('判断是否是苹果支付',channels) 95 + console.log('判断是否是苹果支付', channels)
89 for (var i in channels) { 96 for (var i in channels) {
90 // 判断是否苹果支付 97 // 判断是否苹果支付
91 if (channels[i].id === 'appleiap') { 98 if (channels[i].id === 'appleiap') {
92 that.iapChannel = channels[i] 99 that.iapChannel = channels[i]
93 - that.requestOrder()  
94 - } else {  
95 - // that.payment()  
96 - that.requestOrder() 100 + console.log('判断是否是苹果支付赋值', that.iapChannel)
  101 + // that.requestOrder()
97 } 102 }
98 } 103 }
99 }) 104 })
100 }, 105 },
101 methods: { 106 methods: {
  107 + // {
  108 + // num: 120,
  109 + // price: 12,
  110 + // id: 'TR5CNJF',
  111 + // },
  112 + getMoneyGoods () {
  113 + return new Promise((reslove) => {
  114 + this.$request('/wallet/getMoneyGoods', {type:'ios'}).then((res) => {
  115 + console.log('充值选项列表', res)
  116 + this.list = res.data
  117 + this.list.forEach((item)=>{
  118 + item.num = item.number
  119 + item.price = item.number /10
  120 + })
  121 + reslove(res)
  122 + })
  123 + })
  124 + },
102 //修改支付类型 125 //修改支付类型
103 changePayType(e) { 126 changePayType(e) {
104 - console.log('修改支付类型', e) 127 + console.log('修改支付类型', e)
105 this.param.pay_type = e 128 this.param.pay_type = e
106 }, 129 },
107 //显示支付类型选择弹框 130 //显示支付类型选择弹框
108 showPayType(index) { 131 showPayType(index) {
109 this.price = this.list[index].price 132 this.price = this.list[index].price
110 this.param.number = this.list[index].num 133 this.param.number = this.list[index].num
111 - this.id = this.list[index].id 134 + this.id = this.list[index].apple_goods_id
112 this.param.pay_type = 'wechat' 135 this.param.pay_type = 'wechat'
113 this.showPay = true 136 this.showPay = true
114 }, 137 },
@@ -134,23 +157,24 @@ @@ -134,23 +157,24 @@
134 }, 157 },
135 pay() { 158 pay() {
136 const that = this 159 const that = this
137 - uni.showLoading({  
138 - title: '检测支付环境...',  
139 - mask: true  
140 - })  
141 - plus.payment.getChannels((channels) => {  
142 - console.log('判断是否是苹果支付',channels)  
143 - for (var i in channels) {  
144 - // 判断是否苹果支付  
145 - if (channels[i].id === 'appleiap') {  
146 - that.iapChannel = channels[i]  
147 - that.requestOrder()  
148 - } else {  
149 - // that.payment()  
150 - that.requestOrder()  
151 - }  
152 - }  
153 - }) 160 + // uni.showLoading({
  161 + // title: '检测支付环境...',
  162 + // mask: true
  163 + // })
  164 + // plus.payment.getChannels((channels) => {
  165 + // console.log('判断是否是苹果支付1',channels)
  166 + // for (var i in channels) {
  167 + // // 判断是否苹果支付
  168 + // if (channels[i].id === 'appleiap') {
  169 + // that.iapChannel = channels[i]
  170 + // console.log('判断是否是苹果支付2',that.iapChannel)
  171 + that.requestOrder()
  172 + // } else {
  173 + // that.payment()
  174 + // // that.requestOrder()
  175 + // }
  176 + // }
  177 + // })
154 }, 178 },
155 async payment() { 179 async payment() {
156 console.log('安卓') 180 console.log('安卓')
@@ -177,11 +201,11 @@ @@ -177,11 +201,11 @@
177 requestOrder() { 201 requestOrder() {
178 const that = this 202 const that = this
179 // ['xxxxx'] 是平台申请拿到的内购商品的id 203 // ['xxxxx'] 是平台申请拿到的内购商品的id
180 - console.log('苹果支付')  
181 - that.iapChannel.requestOrder([this.id], 204 + console.log('苹果支付', that.iapChannel)
  205 + that.iapChannel.requestOrder([that.id],
182 function(event) { 206 function(event) {
183 - uni.hideLoading()  
184 - console.log('苹果支付',event) 207 + // uni.hideLoading()
  208 + console.log('苹果支付1', event)
185 for (var index in event) { 209 for (var index in event) {
186 var OrderItem = event[index] 210 var OrderItem = event[index]
187 console.log(OrderItem) 211 console.log(OrderItem)
@@ -189,27 +213,38 @@ @@ -189,27 +213,38 @@
189 } 213 }
190 }, 214 },
191 function(erroemsg) { 215 function(erroemsg) {
192 - uni.hideLoading() 216 + // uni.hideLoading()
  217 + console.log('获取支付通道失败', erroemsg)
193 uni.showToast({ 218 uni.showToast({
194 - title: "获取支付通道失败:" + errormsg.message, 219 + title: "获取支付通道失败:" + erroemsg.message,
195 icon: 'none' 220 icon: 'none'
196 }) 221 })
197 }) 222 })
  223 + console.log('苹果支付', that.iapChannel)
198 }, 224 },
199 - topay(id) { 225 + async topay(id) {
200 const that = this 226 const that = this
  227 + that.param.pay_type = 'ios'
  228 + var orderInfo = await this.getOrderInfo();
201 uni.showLoading({ 229 uni.showLoading({
202 title: '充值中请勿离开', 230 title: '充值中请勿离开',
203 mask: true 231 mask: true
204 }) 232 })
  233 + console.log(id)
205 uni.requestPayment({ 234 uni.requestPayment({
206 provider: 'appleiap', 235 provider: 'appleiap',
207 orderInfo: { 236 orderInfo: {
208 productid: id 237 productid: id
209 }, 238 },
210 success: (res => { 239 success: (res => {
  240 + console.log(1)
  241 + console.log(res)
211 uni.hideLoading() 242 uni.hideLoading()
212 - var orderInfo = this.getOrderInfo(); 243 + this.rechargeIosPay(res.transactionReceipt);
  244 + // 支付成功查询订单
  245 + // plus.payment.request(that.iapChannel, statement, function(res){
  246 + // console.log(res)
  247 + // })
213 }), 248 }),
214 fail: (e) => { 249 fail: (e) => {
215 uni.hideLoading() 250 uni.hideLoading()
@@ -217,14 +252,35 @@ @@ -217,14 +252,35 @@
217 content: "支付失败", 252 content: "支付失败",
218 showCancel: false 253 showCancel: false
219 }) 254 })
  255 + },
  256 + complete: () => {
  257 + console.log("payment结束")
  258 + this.loading = false;
220 } 259 }
221 }) 260 })
222 -  
223 }, 261 },
224 getOrderInfo() { 262 getOrderInfo() {
225 return new Promise((reslove) => { 263 return new Promise((reslove) => {
226 this.$request('/wallet/recharge', this.param).then((res) => { 264 this.$request('/wallet/recharge', this.param).then((res) => {
227 console.log('充值问野币', res) 265 console.log('充值问野币', res)
  266 + this.iosPay.order_id = res.data.order_id
  267 + reslove(res)
  268 + })
  269 + })
  270 + },
  271 + rechargeIosPay(data) {
  272 + this.iosPay.data = data
  273 + return new Promise((reslove) => {
  274 + this.$request('/wallet/rechargeIosPay', this.iosPay).then((res) => {
  275 + console.log('充值问野币ios支付', res)
  276 + uni.navigateBack({
  277 + delta: 1
  278 + })
  279 + setTimeout(() => {
  280 + uni.showToast({
  281 + title: '充值成功'
  282 + })
  283 + }, 500)
228 reslove(res) 284 reslove(res)
229 }) 285 })
230 }) 286 })