| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 | 
							- <?php
 
- namespace app\common\util;
 
- use EasyWeChat\Factory;
 
- use EasyWeChat\Kernel\Exceptions\DecryptException;
 
- use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
 
- use EasyWeChat\Kernel\Support\Collection;
 
- use GuzzleHttp\Exception\GuzzleException;
 
- use Psr\Http\Message\ResponseInterface;
 
- class MiniProgram
 
- {
 
-     public const pay_notify_url = 'https://test.server.ycxxkj.com/deliver/api/public/index.php';
 
-     
 
-     public static function getApp(): object
 
-     {
 
-         $wechat = config('wechat');
 
-         $config = [
 
-             
 
-             'app_id' => $wechat['app_id'],
 
-             'secret' => $wechat['secret'],
 
-             
 
-             
 
-             'response_type' => 'array',
 
-         ];
 
-         return Factory::miniProgram($config);
 
-     }
 
-     
 
-     public static function getPay(): object
 
-     {
 
-         $wechat = config('wechat');
 
-         $config = [
 
-             
 
-             'app_id' => $wechat['app_id'],
 
-             'mch_id' => $wechat['mch_id'],
 
-             'key' => $wechat['key'],
 
-             'cert_path' => $wechat['cert_path'],
 
-             'key_path' => $wechat['key_path'],
 
-             'notify_url' => $wechat['notify_url'],
 
-         ];
 
-         return Factory::payment($config);
 
-     }
 
-     
 
-     public static function getPhoneNumber($code)
 
-     {
 
-         $params = [
 
-             'code' => $code
 
-         ];
 
-         $app = self::getApp();
 
-         return $app->live->httpPostJson('wxa/business/getuserphonenumber', $params);
 
-     }
 
-     
 
-     public static function getPhoneNumberIv($session_key, $iv, $encryptedData): array
 
-     {
 
-         $app = self::getApp();
 
-         return $app->encryptor->decryptData($session_key, $iv, $encryptedData);
 
-     }
 
-     
 
-     public static function nativePay($order_no, $total_fee)
 
-     {
 
-         $app = self::getPay();
 
-         $result = $app->order->unify([
 
-             'trade_type' => 'NATIVE',
 
-             'body' => '快递柜费用',
 
-             'out_trade_no' => $order_no,
 
-             'total_fee' => $total_fee * 100,
 
-             'notify_url' => self::pay_notify_url . '/mobile/payNotify/index',
 
-             'product_id' => 1, 
 
-             
 
-         ]);
 
-         if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
 
-             return QrCode::createEwm($result['code_url']);
 
-         }
 
-         return false;
 
-     }
 
-     
 
-     public static function JsApiPay($order_no, $total_fee, $openid)
 
-     {
 
-         $app = self::getPay();
 
-         $jsSdk = $app->jssdk;
 
-         $result = $app->order->unify([
 
-             'body' => '快递柜费用',
 
-             'out_trade_no' => $order_no,
 
-             'total_fee' => intval($total_fee * 100),
 
-             'notify_url' => self::pay_notify_url . '/api/payNotify/index', 
 
-             'trade_type' => 'JSAPI', 
 
-             'openid' => $openid,
 
-         ]);
 
-         $pay_json = false;
 
-         if ($result['return_code']=='SUCCESS'&&$result['result_code']=='SUCCESS'){
 
-             $pay_json = json_decode($jsSdk->bridgeConfig($result['prepay_id']));
 
-         }
 
-         return $pay_json;
 
-     }
 
-     
 
-     public static function createEwm($param): string
 
-     {
 
-         $app = self::getApp();
 
-         $response = $app->app_code->get(config('ewm.path') . '?' . $param);
 
-         $file_name = self::rand() . '.png';
 
-         $dir = public_path() . 'storage/topic/' . date('Ymd');
 
-         if (!is_dir($dir)) {
 
-             mkdir($dir);
 
-         }
 
-         $saveFile = $dir . '/' . $file_name;
 
-         $url = request()->domain() . getVirRootDir() . '/storage/topic/' . date('Ymd') . '/' . $file_name;
 
-         file_put_contents($saveFile, $response);
 
-         return $url;
 
-     }
 
-     private static function rand()
 
-     {
 
-         $len = 10;
 
-         $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
 
-         $string = time();
 
-         for (; $len >= 1; $len--) {
 
-             $position = rand() % strlen($chars);
 
-             $position2 = rand() % strlen($string);
 
-             $string = substr_replace($string, substr($chars, $position, 1), $position2, 0);
 
-         }
 
-         return $string;
 
-     }
 
- }
 
 
  |