|
@@ -406,7 +406,9 @@
|
|
, function ($scope,$ionicModal,$timeout, $ionicHistory,$ionicTabsDelegate,$state, myService, msg) {
|
|
, function ($scope,$ionicModal,$timeout, $ionicHistory,$ionicTabsDelegate,$state, myService, msg) {
|
|
$scope.$on('$ionicView.beforeEnter', function () {
|
|
$scope.$on('$ionicView.beforeEnter', function () {
|
|
$ionicTabsDelegate.showBar(false);
|
|
$ionicTabsDelegate.showBar(false);
|
|
- $scope.vm = {}
|
|
|
|
|
|
+ $scope.vm = {
|
|
|
|
+
|
|
|
|
+ }
|
|
myService.myInfo().then(function(result){
|
|
myService.myInfo().then(function(result){
|
|
$scope.vm = result.data.data;
|
|
$scope.vm = result.data.data;
|
|
$scope.vm.number = '';
|
|
$scope.vm.number = '';
|
|
@@ -449,79 +451,102 @@
|
|
$scope.$on('$destroy', function() {
|
|
$scope.$on('$destroy', function() {
|
|
$scope.modal.remove();
|
|
$scope.modal.remove();
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ $scope.ios={
|
|
|
|
+ isIOS:ionic.Platform.isIOS(),
|
|
|
|
+ productid:''
|
|
|
|
+ }
|
|
|
|
+
|
|
//充值
|
|
//充值
|
|
$scope.charge = function(number){
|
|
$scope.charge = function(number){
|
|
- if (!number) {
|
|
|
|
- msg.text('请输入充值金额');
|
|
|
|
- return;
|
|
|
|
|
|
+ if($scope.ios.isIOS){
|
|
|
|
+ if ($scope.ios.productid.length<2){
|
|
|
|
+ msg.text('请选择充值金额');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ inAppPurchase
|
|
|
|
+ .buy($scope.ios.productid)
|
|
|
|
+ .then(function (data) {
|
|
|
|
+ return inAppPurchase.consume(data.productType, data.receipt, data.signature);
|
|
|
|
+ })
|
|
|
|
+ .then(function () {
|
|
|
|
+ msg.success('购买成功');
|
|
|
|
+ $ionicHistory.goBack();
|
|
|
|
+ })
|
|
|
|
+ .catch(function (err) {
|
|
|
|
+ alert('购买失败:'+err);
|
|
|
|
+ });
|
|
|
|
+ }else{
|
|
|
|
+ if (!number) {
|
|
|
|
+ msg.text('请输入充值金额');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ myService.charge(number,2).then(function (result) {
|
|
|
|
+ //todo:result需要返回支付宝或者微信的签名信息
|
|
|
|
+ console.log("result: " + JSON.stringify(result));
|
|
|
|
+ var payInfo = result.data.data;
|
|
|
|
+ var orderID = payInfo.transaction_id
|
|
|
|
+ $scope.vm.transaction_id = payInfo.transaction_id;
|
|
|
|
+ $scope.vm.price = payInfo.price;
|
|
|
|
+ if ($scope.vm.payType == 1) { //支付宝
|
|
|
|
+ cordova.plugins.AliPay.pay(payInfo, function success(e) {
|
|
|
|
+ //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
|
|
|
|
+ //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
|
|
|
|
+ //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
|
|
|
|
+ //当e.resultStatus为9000时,请去服务端验证支付结果
|
|
|
|
+ $scope.clicksub = false;
|
|
|
|
+ if (e.resultStatus == '9000') {
|
|
|
|
+ alert(orderID);
|
|
|
|
+ //支付成功
|
|
|
|
+ // $state.go('app.my');
|
|
|
|
+ } else {
|
|
|
|
+ msg.error("支付失败");
|
|
|
|
+ // msg.error("支付失败:" + JSON.stringify(e));
|
|
|
|
+ }
|
|
|
|
+ }, function error(e) {
|
|
|
|
+ $scope.clicksub = false;
|
|
|
|
+ // msg.error("支付失败:" + JSON.stringify(e));
|
|
|
|
+ msg.error("支付失败");
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if ($scope.vm.payType == 2) { //微信
|
|
|
|
+ // var obj = JSON.parse(payInfo);
|
|
|
|
+ var obj = payInfo.orderString;
|
|
|
|
+ // console.log("obj: " + JSON.stringify(obj));
|
|
|
|
+ var params = {
|
|
|
|
+ partnerid: obj.partnerid, // merchant id
|
|
|
|
+ prepayid: obj.prepayid, // prepay id
|
|
|
|
+ noncestr: obj.noncestr, // nonce
|
|
|
|
+ timestamp: obj.timestamp, // timestamp
|
|
|
|
+ sign: obj.sign, // signed string
|
|
|
|
+ };
|
|
|
|
+ // console.log("result: " + JSON.stringify(params));
|
|
|
|
+ Wechat.sendPaymentRequest(params, function (r) {
|
|
|
|
+ $scope.clicksub = false;
|
|
|
|
+ // $state.go("app.paySuccess")
|
|
|
|
+ // $state.go('app.paySuccess',{item:payInfo})
|
|
|
|
+ $scope.openModal();
|
|
|
|
+ // alert(orderID);
|
|
|
|
+ myService.orderStatus(orderID).then(function (result) {
|
|
|
|
+ // alert(result);
|
|
|
|
+ //支付成功
|
|
|
|
+ // $state.go('app.my');
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }, function (erro) {
|
|
|
|
+ // msg.alert("支付反馈失败:" + JSON.stringify(erro));
|
|
|
|
+ });
|
|
|
|
+ }, function (reason) {
|
|
|
|
+ $scope.clicksub = false;
|
|
|
|
+ // msg.alert("支付失败:" + JSON.stringify(reason));
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // msg.text("充值成功");
|
|
|
|
+ // $state.go('app.my');
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- myService.charge(number,2).then(function (result) {
|
|
|
|
- //todo:result需要返回支付宝或者微信的签名信息
|
|
|
|
- console.log("result: " + JSON.stringify(result));
|
|
|
|
- var payInfo = result.data.data;
|
|
|
|
- var orderID = payInfo.transaction_id
|
|
|
|
- $scope.vm.transaction_id = payInfo.transaction_id;
|
|
|
|
- $scope.vm.price = payInfo.price;
|
|
|
|
- if ($scope.vm.payType == 1) { //支付宝
|
|
|
|
- cordova.plugins.AliPay.pay(payInfo, function success(e) {
|
|
|
|
- //e.resultStatus 状态代码 e.result 本次操作返回的结果数据 e.memo 提示信息
|
|
|
|
- //e.resultStatus 9000 订单支付成功 ;8000 正在处理中 调用function success
|
|
|
|
- //e.resultStatus 4000 订单支付失败 ;6001 用户中途取消 ;6002 网络连接出错 调用function error
|
|
|
|
- //当e.resultStatus为9000时,请去服务端验证支付结果
|
|
|
|
- $scope.clicksub = false;
|
|
|
|
- if (e.resultStatus == '9000') {
|
|
|
|
- alert(orderID);
|
|
|
|
- //支付成功
|
|
|
|
- // $state.go('app.my');
|
|
|
|
- } else {
|
|
|
|
- msg.error("支付失败");
|
|
|
|
- // msg.error("支付失败:" + JSON.stringify(e));
|
|
|
|
- }
|
|
|
|
- }, function error(e) {
|
|
|
|
- $scope.clicksub = false;
|
|
|
|
- // msg.error("支付失败:" + JSON.stringify(e));
|
|
|
|
- msg.error("支付失败");
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- if ($scope.vm.payType == 2) { //微信
|
|
|
|
- // var obj = JSON.parse(payInfo);
|
|
|
|
- var obj = payInfo.orderString;
|
|
|
|
- // console.log("obj: " + JSON.stringify(obj));
|
|
|
|
- var params = {
|
|
|
|
- partnerid: obj.partnerid, // merchant id
|
|
|
|
- prepayid: obj.prepayid, // prepay id
|
|
|
|
- noncestr: obj.noncestr, // nonce
|
|
|
|
- timestamp: obj.timestamp, // timestamp
|
|
|
|
- sign: obj.sign, // signed string
|
|
|
|
- };
|
|
|
|
- // console.log("result: " + JSON.stringify(params));
|
|
|
|
- Wechat.sendPaymentRequest(params, function (r) {
|
|
|
|
- $scope.clicksub = false;
|
|
|
|
- // $state.go("app.paySuccess")
|
|
|
|
- // $state.go('app.paySuccess',{item:payInfo})
|
|
|
|
- $scope.openModal();
|
|
|
|
- // alert(orderID);
|
|
|
|
- myService.orderStatus(orderID).then(function (result) {
|
|
|
|
- // alert(result);
|
|
|
|
- //支付成功
|
|
|
|
- // $state.go('app.my');
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- }, function (erro) {
|
|
|
|
- // msg.alert("支付反馈失败:" + JSON.stringify(erro));
|
|
|
|
- });
|
|
|
|
- }, function (reason) {
|
|
|
|
- $scope.clicksub = false;
|
|
|
|
- // msg.alert("支付失败:" + JSON.stringify(reason));
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // msg.text("充值成功");
|
|
|
|
- // $state.go('app.my');
|
|
|
|
- });
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}]);
|
|
}]);
|
|
|
|
|
|
app.controller('accountCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
|
|
app.controller('accountCtrl', ["$scope","$ionicTabsDelegate", "$state", "myService", "msg"
|