MemberCardController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. namespace app\payment\controllers;
  3. use app\common\helpers\Url;
  4. use app\common\models\AccountWechats;
  5. use app\common\services\Pay;
  6. use app\payment\PaymentController;
  7. class MemberCardController extends PaymentController
  8. {
  9. private $data = [];
  10. private $orderSn = '';
  11. public function preAction()
  12. {
  13. parent::preAction();
  14. //
  15. // if (empty(\YunShop::app()->uniacid)) {
  16. // $res = $this->getPost();
  17. // if($res === true){
  18. // \Setting::$uniqueAccountId = \YunShop::app()->uniacid = request()->input('uniacid');
  19. // AccountWechats::setConfig(AccountWechats::getAccountByUniacid(\YunShop::app()->uniacid));
  20. // }
  21. //
  22. // }
  23. }
  24. /**
  25. * JSAPI 回调
  26. */
  27. public function notifyUrl()
  28. {
  29. // $this->log($this->data);
  30. // \Log::info('-------this->data---------',$this->data);
  31. // // 微信
  32. // if ($this->data['source'] == 1 && $this->data['state'] ==2) {
  33. // \Log::info('------验证成功-----');
  34. // $data = [
  35. // 'total_fee' => floatval($this->data['truemoney']),
  36. // 'out_trade_no' => $this->orderSn,
  37. // 'trade_no' => $this->data['oid'],
  38. // 'unit' => 'yuan',
  39. // 'pay_type' => '云支付',
  40. // 'pay_type_id' => 33
  41. // ];
  42. // $this->payResutl($data);
  43. // \Log::info('----结束----');
  44. // echo "success";
  45. // } else {
  46. // echo "fail";
  47. // }
  48. }
  49. /**
  50. * 小程序回调
  51. */
  52. public function notifyMiniAppUrl()
  53. {
  54. //todo 验证签名在此方法下进行
  55. // $data = $this->getPost();
  56. // $this->log($this->data);
  57. // $this->getSignResult($data['paySign']);
  58. // if ($this->data['source'] == 2 && $this->data['state'] ==2) {
  59. // if($this->getQuery() !== true){
  60. // echo 'fail';exit();
  61. // }
  62. // \Log::debug('------验证成功-----');
  63. // $data = [
  64. // 'total_fee' => floatval($this->data['truemoney']),
  65. // 'out_trade_no' => $this->orderSn,
  66. // 'trade_no' => $this->data['oid'],
  67. // 'unit' => 'yuan',
  68. // 'pay_type' => '会员卡',
  69. // 'pay_type_id' => 53
  70. // ];
  71. //
  72. // $this->payResutl($data);
  73. // \Log::debug('----结束----');
  74. // echo "success";
  75. // } else {
  76. // echo "fail";
  77. // }
  78. }
  79. public function getPost()
  80. {
  81. //支付回调接口(jsapi支付)
  82. //获取xml
  83. // $xmlData = file_get_contents('php://input');
  84. // libxml_disable_entity_loader(true);
  85. // //转换成数组
  86. // $rsdata = json_decode(json_encode(simplexml_load_string($xmlData, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
  87. // \Log::info($rsdata);
  88. // ksort($rsdata);
  89. // if(empty($rsdata)){
  90. // return true;
  91. // }
  92. // $this->data = $rsdata;
  93. // if($this->data){
  94. // $data = explode(':', $this->data['olid']);
  95. // $this->orderSn = $data['0'];
  96. // \Log::info($data['0']);
  97. // \Log::info($data['1']);
  98. // \Setting::$uniqueAccountId = \YunShop::app()->uniacid = $data['1'];
  99. // }
  100. // AccountWechats::setConfig(AccountWechats::getAccountByUniacid(\YunShop::app()->uniacid));
  101. //
  102. // $buff = '';
  103. // foreach ($rsdata as $k => $v){
  104. // if($k != 'sign'){
  105. // $buff .= $k . '=' . $v . '&';
  106. // }
  107. // }
  108. //
  109. // $stringSignTemp = $buff .'key='.\Setting::get('plugin.jueqi_pay_set.key'); //支付秘钥
  110. // \Log::info('-------key---------',\Setting::get('plugin.jueqi_pay_set.key'));
  111. // \Log::info('-------stringSignTemp---------',$stringSignTemp);
  112. // $sign = strtoupper(md5($stringSignTemp));//生成签名
  113. // \Log::info('-------sign---------',$sign);
  114. // //验证签名
  115. // if($sign == $rsdata['sign']){
  116. // return $rsdata;
  117. // }else{
  118. // \Log::info("data-no:".$xmlData );
  119. // exit('FAIL');
  120. // }
  121. }
  122. /**
  123. * 成功跳转页面
  124. * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  125. */
  126. public function returnUrl()
  127. {
  128. redirect(Url::absoluteApp('home'))->send();
  129. }
  130. public function frontUrl()
  131. {
  132. // $trade = \Setting::get('shop.trade');
  133. //
  134. // if (!is_null($trade) && isset($trade['redirect_url']) && !empty($trade['redirect_url'])) {
  135. // return redirect($trade['redirect_url'])->send();
  136. // }
  137. //
  138. // if (0 == $_GET['state'] && $_GET['errorDetail'] == '成功') {
  139. // redirect(Url::absoluteApp('member', ['i' => $_GET['attach']]))->send();
  140. // } else {
  141. // redirect(Url::absoluteApp('member', ['i' => $_GET['attach']]))->send();
  142. // }
  143. }
  144. /**
  145. * 支付日志
  146. *
  147. * @param $post
  148. */
  149. public function log($data)
  150. {
  151. //访问记录
  152. Pay::payAccessLog();
  153. //保存响应数据
  154. Pay::payResponseDataLog($data['olid'], '会员卡', json_encode($data));
  155. }
  156. private function getQuery()
  157. {
  158. //订单查询接口
  159. // $stringSignTemp = 'olid='.$this->data['olid'].'&key='.\Setting::get('plugin.jueqi_pay_set.key'); //支付秘钥
  160. // $sign = strtoupper(md5($stringSignTemp));//生成签名
  161. //
  162. // $post_data['olid'] = $this->data['olid']; //唯一标识
  163. // $post_data['sign'] = $sign; //签名
  164. // $url = \Setting::get('plugin.jueqi_pay_set.order_query');
  165. // $ch = curl_init();
  166. // curl_setopt($ch, CURLOPT_URL, $url);
  167. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  168. // // post数据
  169. // curl_setopt($ch, CURLOPT_POST, 1);
  170. // // post的变量
  171. // curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  172. // $output = curl_exec($ch);
  173. // curl_close($ch);
  174. // //获取xml
  175. // libxml_disable_entity_loader(true);
  176. // $rsdata = json_decode(json_encode(simplexml_load_string($output, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
  177. // if($rsdata['state'] == 2){
  178. // return true;
  179. // }else{
  180. // \Log::debug($rsdata['errordesc']);
  181. // }
  182. }
  183. }