吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2402|回复: 24
收起左侧

[其他原创] [ios]ios复制优惠券打开淘宝(连载12)

  [复制链接]
debug_cat 发表于 2021-3-27 21:27
国际惯例,先看看我们的成果。
open-taobao.gif




开发环境

Xocde 12.4

Swift 5.3

Mac OS 10.15.6

生成商品优惠券

接口

https://api.sunofbeach.net/shop/tpwd

post

body:
{
    "title":"商品的title",
    "url"  :"https: + couponClickUrl"
}

//返回数据
{
    "success": true,
    "code": 10000,
    "message": "淘宝口令构建成功!",
    "data": {
        "tbk_tpwd_create_response": {
            "data": {
                "model": "4¥rm11X0tDlMV¥ https://m.tb.cn/h.4Mybft3  亲亲纯蛋糕400g零食早餐速食整箱懒人面包手工鸡蛋糕點营养食品"
            },
            "request_id": "nx55f5sw7i9b"
        }
    }
}

编写返回数据的模型

把上面返回的json复制,然后打开软件JSONExport。选择swift,object mapping一件生成。

请求接口部分

func getCoupons() {
        //获取优惠券
        //let paraData = CouponsPara(title: goodsData?.title ?? "", url: goodsData?.couponClickUrl ?? "")
            //获取优惠券的url
        let clickUrl = goodsData?.couponClickUrl ?? ""
            //拼接https
        let targetUrl = "https:\(clickUrl)"
        let paraData: NSDictionary = ["title":goodsData?.title ?? "", "url":targetUrl]
        let headers = [
            "Content-Type": "application/json"
        ]

        Alamofire.request(UnionApi.getCouponsUrl(), method: .post, parameters: paraData as! Parameters,encoding: JSONEncoding.default, headers: headers).responseObject{  (response: DataResponse<CouponsResult>) in
            let data = response.result.value
            //print(data?.data?.tbkTpwdCreateResponse?.data?.model)
            //显示优惠券数据
            if let model = data?.data?.tbkTpwdCreateResponse?.data?.model{
                self.labCouponContent.text = model
            }
        }
}

获取成功之后,显示到页面上面就行了。设置text。

把优惠券复制到粘贴板和打开淘宝

image

复制文本到粘贴板很简单

UIPasteboard.general.string = "需要放到粘贴板的文本"

打开一个窗口,让我们选择是否直接打开淘宝

// 复制到粘贴板中
    @objc func copyToPasteboard(sender: UIButton){
        //UIPasteboard.general.string = self.labCouponContent.text
        let pboard = UIPasteboard.general
        pboard.string = self.labCouponContent.text

        let titleStr = "淘口令复制成功,是否跳转到手机淘宝APP?"
        let jumpStr = "taobao://item.taobao.com/item.htm"

        let alertCtr = UIAlertController.init(title: titleStr, message: nil, preferredStyle: UIAlertController.Style.alert)
        alertCtr.addAction(UIAlertAction.init(title: "取消", style: UIAlertAction.Style.cancel, handler: nil))
        alertCtr.addAction(UIAlertAction.init(title: "确定", style: UIAlertAction.Style.default, handler: { (action) in

            if let url = URL.init(string: jumpStr) {

                if UIApplication.shared.canOpenURL(url) == true {
                    UIApplication.shared.openURL(url)
                } else {

                    let alertC = UIAlertController.init(title: "您未安装手机淘宝APP,是否前往AppStore下载安装?", message: nil, preferredStyle: UIAlertController.Style.alert)

                    alertC.addAction(UIAlertAction.init(title: "取消", style: UIAlertAction.Style.cancel, handler: nil))
                    alertC.addAction(UIAlertAction.init(title: "确定", style: UIAlertAction.Style.default, handler: { (action: UIAlertAction) in

                        let AppStoreVC = UIViewController.init()
                        AppStoreVC.modalTransitionStyle = UIModalTransitionStyle.coverVertical

                        let webView = UIWebView.init(frame: AppStoreVC.view.bounds)
                        let request = NSURLRequest.init(url: URL.init(string: "itms-apps://itunes.apple.com/cn/app/tao-bao-sui-shi-sui-xiang/id387682726?mt=8")!) //AppStore手机淘宝地址
                        webView.loadRequest(request as URLRequest)
                        AppStoreVC.view.addSubview(webView)

                        self.present(AppStoreVC, animated: true, completion: {
                            AppStoreVC.dismiss(animated: true, completion: nil)
                        })
                    }))
                    self.present(alertC, animated: true, completion: nil)

                }
            }
        }))
        self.present(alertCtr, animated: true, completion: nil)
    }

这样打开,是会失败的,我们还需要在info.plist中配置一个值,支持打开淘宝和天猫

LSApplicationQueriesSchemes
Array类型
保存2个值,taobao,tmall

代码地址:

https://github.com/cat13954/IOSUiTableViewSample

最近比较忙,一个星期没更新了,今天就先到这里先啦

下一篇文章的内容,应该是显示多个不同类型的商品列表


免费评分

参与人数 5吾爱币 +11 热心值 +5 收起 理由
sob13600 + 1 + 1 谢谢@Thanks!
mo211683 + 1 + 1 用心讨论,共获提升!
苏紫方璇 + 7 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
99910369 + 1 + 1 谢谢@Thanks!
lyl610abc + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| debug_cat 发表于 2021-3-30 09:02
dxaw2458 发表于 2021-3-29 19:00
好吧 我还是慢慢的先把你的帖子看完先     就一台电脑 win     有ios开发的基础教程没 ?

https://www.bilibili.com/video/BV144411C7Gg
https://www.bilibili.com/video/B ... ommend_more_video.1
我是看这2个自学的。
熟悉oc基础,然后熟悉swift的基础,就直接开始写app了。遇到不懂的就查。
 楼主| debug_cat 发表于 2021-3-27 23:38
如此如何 发表于 2021-3-27 23:35
怎么使用啊 看不懂

开发环境xocde 12,语言swift 5+。
这个iOS的app来的。需要swift基础才好看,如果你有其他语言基础也很好学习的。
你可以翻翻,我个人中心,里面我已经写了10篇文章了,从最开始的页面编写,到现在这样模样。
文章末尾有整个项目的代码。直接下载就行了。
lyl610abc 发表于 2021-3-27 21:33
cjc3528 发表于 2021-3-27 21:43
太厉害了,这下就方便了
盐帮仙人 发表于 2021-3-27 21:43
感谢楼主分享
 楼主| debug_cat 发表于 2021-3-27 22:29
lyl610abc 发表于 2021-3-27 21:33
好家伙,又更新了,太快了吧

离开家里一周了,今天得补回来了,很舒服
 楼主| debug_cat 发表于 2021-3-27 22:30
cjc3528 发表于 2021-3-27 21:43
太厉害了,这下就方便了

哈哈,我是一个小萌新,如何喜欢一起学习
lyl610abc 发表于 2021-3-27 22:44
莫问刀 发表于 2021-3-27 22:30
哈哈,我是一个小萌新,如何喜欢一起学习

大佬又开始装萌新了
我才是真萌新
Xiao伟 发表于 2021-3-27 22:50
微信中打开复制 会提示跳转吗
99910369 发表于 2021-3-27 23:25
谢谢老板热心分享,~~
aa361328 发表于 2021-3-27 23:29
感谢分享哈~~~~~~~~~~~~~~~~
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-4 14:15

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表