AggregateQrcodeForm.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\models\v1;
  8. use app\models\AggregateQrcode;
  9. use app\models\Option;
  10. use app\models\WechatConfig;
  11. use EasyWeChat\Factory;
  12. use yii\base\Model;
  13. class AggregateQrcodeForm extends Model
  14. {
  15. public $id;
  16. public $store_id;
  17. //获取支付宝配置信息
  18. public function rules()
  19. {
  20. return [
  21. [["id", "store_id"],'integer']
  22. ];
  23. }
  24. public function AliConfig(){
  25. $qrcode = AggregateQrcode::findOne($this->id);
  26. //支付宝配置
  27. $value = Option::get(Option::OPTOPN_KEY, $qrcode->store_id, 'alipay');
  28. $ali_config = json_decode($value['value'],true);
  29. $url = "https://ds.alipay.com/?scheme=".urlencode("alipays://platformapi/startapp?appId={$ali_config['app_id']}&page={$qrcode->ali_url}&query=id=").$this->id;
  30. return [
  31. 'code'=>0,
  32. 'msg'=>"获取成功",
  33. 'data'=>[
  34. 'url'=>$url
  35. ]
  36. ];
  37. }
  38. //获取微信配置信息
  39. public function wxConfig(){
  40. $qrcode = AggregateQrcode::findOne($this->id);
  41. $wechatConfig = WechatConfig::find()->where(['store_id' => $qrcode->store_id])->select('id,store_id,app_id,app_secret,gh_id')->asArray()->one();
  42. $config = [
  43. 'app_id' => $wechatConfig['app_id'],
  44. 'secret' => $wechatConfig['app_secret'],
  45. 'response_type' => 'array',
  46. ];
  47. $app = Factory::officialAccount($config);
  48. $wxConfig = $app->jssdk->buildConfig([], $debug = false, $beta = false, $json = true);
  49. $wxConfig = json_encode($wxConfig);
  50. $wxConfig['gh_id'] = $wechatConfig['gh_id'];
  51. return [
  52. 'code'=>0,
  53. 'msg'=>"获取成功",
  54. 'data'=>$wxConfig
  55. ];
  56. }
  57. }