Browse Source

get paid unionid

master
weigang 5 years ago
parent
commit
709248d23d
  1. 17
      app/Controller/v3/NotifyController.php
  2. 9
      app/Service/v3/Implementations/UserInfoService.php
  3. 2
      app/Service/v3/Interfaces/UserInfoServiceInterface.php

17
app/Controller/v3/NotifyController.php

@ -197,6 +197,15 @@ class NotifyController extends BaseController
// 公众号模板消息 // 公众号模板消息
$res = $this->miniprogramService->sendTemMsgForOnlineOrder($orderMain->global_order_id); $res = $this->miniprogramService->sendTemMsgForOnlineOrder($orderMain->global_order_id);
co(function () use ($orderMain) {
$openid = User::query()->where(['id' => $orderMain->user_id])->value('openid');
$unionid = $this->userInfoService->getPaidUnionId($openid, ['mch_id' => config('wxpay.mch_id'), 'out_trade_no' => $orderMain->global_order_id]);
if ($unionid) {
User::query()->where(['id' => $orderMain->user_id, 'openid' => $openid])->update(['unionid' => $unionid]);
}
});
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
@ -285,9 +294,13 @@ class NotifyController extends BaseController
// 公众号模板消息 // 公众号模板消息
$res = $this->miniprogramService->sendTemMsgForOfflineOrder($orderMain->global_order_id); $res = $this->miniprogramService->sendTemMsgForOfflineOrder($orderMain->global_order_id);
co(function () use ($orderMain) {
$openid = User::query()->where(['id' => $orderMain->user_id])->value('openid'); $openid = User::query()->where(['id' => $orderMain->user_id])->value('openid');
$res = $this->userInfoService->getPaidUnionId($openid);
$this->log->event('test_get_paid_unionid', ['res' => $res]);
$unionid = $this->userInfoService->getPaidUnionId($openid, ['mch_id' => config('wxpay.mch_id'), 'out_trade_no' => $orderMain->global_order_id]);
if ($unionid) {
User::query()->where(['id' => $orderMain->user_id, 'openid' => $openid])->update(['unionid' => $unionid]);
}
});
return true; return true;

9
app/Service/v3/Implementations/UserInfoService.php

@ -103,11 +103,16 @@ class UserInfoService implements UserInfoServiceInterface
return $employees; return $employees;
} }
public function getPaidUnionId($openid)
public function getPaidUnionId($openid, $options = [])
{ {
$config = config('applet'); $config = config('applet');
$app = Factory::miniProgram($config); $app = Factory::miniProgram($config);
$app['guzzle_handler'] = CoroutineHandler::class; $app['guzzle_handler'] = CoroutineHandler::class;
return $app->base->getPaidUnionid($openid);
$res = $app->base->getPaidUnionid($openid, $options);
if (isset($res['unionid']) && $res['unionid']) {
return $res['unionid'];
} else {
return false;
}
} }
} }

2
app/Service/v3/Interfaces/UserInfoServiceInterface.php

@ -10,5 +10,5 @@ interface UserInfoServiceInterface
public function detail($userId); public function detail($userId);
public function getStoreByUID($userId); public function getStoreByUID($userId);
public function getEmployeesByUID($userId); public function getEmployeesByUID($userId);
public function getPaidUnionId($openid);
public function getPaidUnionId($openid, $options = []);
} }
Loading…
Cancel
Save