PK creative Spring Festival, I am participating in the “Spring Festival creative submission contest”, please see: Spring Festival creative submission Contest

The effect

experience Send page Get the page New Year greeting posture recognition page

introduce

The project is mainly divided into three parts – small program send red envelope, get red envelope, posture collection – back-end login, send red envelope, pay, get red envelope, send money, verify whether the posture is correct – human body recognition to identify the key points of the human body when the picture is collected

1. The small program

  • Developed using UNI-app
  • The UI using uview
  • Currently only compatible with wechat small programs
  • There are three pages

2. The back end

  • Using Java development
  • The framework is mainly to Springboot + Mybatis -plus + ijpay-wxpay + redisson

3. Body recognition

  • Developing with Python
  • The framework is mainly Django + PaddlePaddle

First, give red envelopes

  • Sender default wechat obtained nickname, can be customized, convenient for different people to write different names
  • Currently, there are three ways to collect them
    • Open: open the red envelope to receive directly
    • Write a message: after filling in the message, you can open the red envelope
    • Gesture New Year’s greetings: need to make New Year’s greetings, do right after you can receive
  • Train of thought
    • Small procedures to fill in red envelope information, request the server
    • The server saves the red envelope and calls wechat Pay to generate wechat Pay orders, which are returned to the small program
    • The small program gets the required parameters of wechat Pay and invokes wechat Pay
    • After the payment is successful, the small program queries the result of the server. After confirming the payment is successful, a success message pops up
  • Code implementation
    • Page (using a simple UI framework)
    <view style="margin: 20rpx;">
        <u--form labelPosition="left" labelWidth="80" :model="from_data">
                <u-form-item label="Sender">
                        <u--input v-model="from_data.nickName" border="none" maxlength="20" color="#FFFFFF">
                        </u--input>
                </u-form-item>
                <u-form-item label="Number of Lucky money">
                        <u--input v-model="from_data.num" border="none" type="number" maxlength="3" color="#FFFFFF">
                        </u--input>
                </u-form-item>
                <u-form-item label="Lucky Money Amount">
                        <u--input v-model="from_data.amount" border="none" type="digit" maxlength="Seven" color="#FFFFFF">
                        </u--input>
                </u-form-item>
                <u-form-item label="Lucky Money Type">
                        <u-radio-group v-model="from_data.redPacketType" placement="row">
                                <u-radio :customStyle="{marginRight: '16rpx'}" v-for="(item, index) in redPacket_type"
                                        :key="index" :label="item.name" :name="item.name" labelColor="#FFFFFF">
                                </u-radio>
                        </u-radio-group>
                </u-form-item>
                <u-form-item label="Method of Collection">
                        <u-radio-group v-model="from_data.receivingMethod" placement="row">
                                <u-radio :customStyle="{marginRight: '16rpx'}" v-for="(item, index) in receiving_method"
                                        :key="index" :label="item.name" :name="item.name" :disabled="item.disabled"
                                        labelColor="#FFFFFF">
                                </u-radio>
                        </u-radio-group>
                </u-form-item>
                <u-form-item label="Leave a message.">
                        <u--input v-model="from_data.redPacketBlessing" border="none" maxlength="30" color="#FFFFFF">
                        </u--input>
                </u-form-item>
        </u--form>
        <u-alert title="A 3% handling fee is required including (wechat Pay and operating expenses)" type="error" effect="dark" closable></u-alert>
        <u-button type="primary" :loading="pay_loading_show" loadingText="In payment..." text="Pay" throttleTime="1000"
                customStyle="margin-top: 10rpx" @click="pay">
        </u-button>
    </view>
    
    Copy the code
    • Js (give red envelopes, pay)
    pay() {
        // Verify the form
        let num = this.from_data.num
        let fee = this.from_data.amount * 100
        let redPacketType = this.from_data.redPacketType
        if (num < 1) {
            uni.showToast({
                    title: 'At least 1 gift of Lucky Money'
            })
            return
        } else if (num > 500) {
            uni.showToast({
                    title: 'Up to 500 copies of Lucky Money'
            })
            return
        }
        if (redPacketType == 'Fight your Luck') {
            if (fee / num < 30) {
                uni.showToast({
                        title: 'Minimum $0.3 for single person'
                })
                return
            } else if (fee / num > 10000) {
                uni.showToast({
                        title: 'Up to $100 per person'
                })
                return}}else if (redPacketType == 'share') {
            if (fee < 30) {
                uni.showToast({
                        title: 'Minimum $0.3 for single person'
                })
                return
            } else if (fee > 10000) {
                uni.showToast({
                        title: 'Up to $100 per person'
                })
                return}}/ / form
        let that = this
        this.pay_loading_show = true
        let from = {
            nickName: this.from_data.nickName,
            num: this.from_data.num,
            amount: this.from_data.amount,
            redPacketBlessing: this.from_data.redPacketBlessing
        }
        if (this.from_data.redPacketType == 'Fight your Luck') {
                from.redPacketType = 1
        } else if (this.from_data.redPacketType == 'share') {
                from.redPacketType = 2
        }
        if (this.from_data.receivingMethod == 'Open it.') {
                from.receivingMethod = 1
        } else if (this.from_data.receivingMethod == 'Write a message') {
                from.receivingMethod = 2
        } else if (this.from_data.receivingMethod == 'New Year greetings with gestures') {
                from.receivingMethod = 3
        }
        // Generate a red envelope order
        uni.$u.http.post('/redPacket/send'.from).then(res= > {
                console.log(JSON.stringify(res))
                that.currentRedPacketId = res.redPacketId
                //res is the argument to pay for the result returned after the order is generated
                // Return to invoke wechat pay
                wx.requestPayment({
                        timeStamp: res.timeStamp,
                        nonceStr: res.nonceStr,
                        package: res.package,
                        signType: res.signType,
                        paySign: res.paySign,
                        success(res) {
                                console.log('Payment successful')
                                that.currentRedPacket = that.from_data
                                // Query the payment result after successful payment
                                that.queryPayRes(1)},fail(res) {
                                console.log('Payment failure')
                                that.pay_loading_show = false
                                that.refreshRedPacket()
                                uni.showToast({
                                        title: 'Payment failure'})}})})},// Query the payment result
    // Select * from * where * /
    queryPayRes(count) {
        if (count == null) {
                count = 1
        }
        uni.$u.http.post('/redPacket/queryPay', {
                redPacketId: this.currentRedPacketId
        }).then(res= > {
                console.log('Query payment result:' + JSON.stringify(res))
                console.log('Query payment result:' + res)
                if (res == true) {
                        // Cancel loading after the payment is successful
                        this.pay_show = true
                        this.pay_loading_show = false
                        this.refreshRedPacket()
                } else {
                        if (count < 30) {
                                setTimeout(() = > {
                                        this.queryPayRes(++count)
                                }, 500)}else {
                                this.pay_fail_show = true
                                this.pay_loading_show = false
                                this.refreshRedPacket()
                        }
                }
        })
    },
    Copy the code
    • Java back-end red envelope interface
    @Override
    publicResult<? > send(UserBo user, RedPacketVo redPacketVo) {// Check parameters
        double fee = NumberUtil.mul(redPacketVo.getAmount(), new Double(100.00));
        if (redPacketVo.getNum() > fee) {
            return Result.parameterError("At least one penny per person.");
        }
        Integer redPacketType = redPacketVo.getRedPacketType();
        Integer receivingMethod = redPacketVo.getReceivingMethod();
        if (redPacketType == null || receivingMethod == null) {
            return Result.parameterError();
        }
        // Generate red packets
        RedPacket redPacket = new RedPacket()
                .setNum(redPacketVo.getNum())
                .setRedPacketBlessing(redPacketVo.getRedPacketBlessing())
                .setRedPacketType(redPacketType)
                .setReceivingMethod(receivingMethod)
                .setNickName(redPacketVo.getNickName())
                .setUserId(user.getUserId())
                .setStatus(0)
                .setOutTradeNo(WxPayKit.generateStr());
        if (redPacketType.equals(1BigDecimal roundTotalFee = NumberUtil. Round (fee,0);
            redPacket.setTotalFee(roundTotalFee.intValue());
            redPacket.setPayTotalFee(NumberUtil.mul(roundTotalFee, 1.03).intValue());
            // Red envelope algorithm (can have fair version, can also have hand speed version, so it is not necessarily a big red envelope, hahaha)
            List<Integer> redPacketFeeList = doubleMeanMethod(redPacket.getTotalFee(), redPacketVo.getNum());
            // The amount of each red envelope is saved
            redPacket.setRedPacketFeeList(redPacketFeeList);
        } else if (redPacketType.equals(2)) {
            // Divide the red packets equally, and calculate the total amount
            double totalFee = NumberUtil.mul(fee, redPacketVo.getNum().longValue());
            BigDecimal roundTotalFee = NumberUtil.round(totalFee, 0);
            redPacket.setTotalFee(roundTotalFee.intValue());
            redPacket.setPayTotalFee(NumberUtil.mul(roundTotalFee, 1.03).intValue());
            // The amount of each red envelope is saved
            List<Integer> redPacketFeeList = new ArrayList<>();
            int roundFee = NumberUtil.round(fee, 0).intValue();
            for (int i = 0; i < redPacketVo.getNum(); i++) {
                redPacketFeeList.add(roundFee);
            }
            redPacket.setRedPacketFeeList(redPacketFeeList);
        }
        // Save the red envelope
        boolean save = save(redPacket);
        if (save) {
            // Call the wechat pay interface to produce wechat Pay orders
            Map<String, String> data = weChatPayService.miniAppPay(user, redPacket);
            data.put("redPacketId", redPacket.getRedPacketId().toString());
            // Return the payment parameters required by wechat Pay
            return Result.success(data);
        }
        return Result.exceptionError("Failed to send red envelopes");
    }
    
    /** ** Double mean + Minimum amount algorithm (fair version) **@paramTotalFee *@paramSize Number of recipients */
    public static List<Integer> doubleMeanMethod(int totalFee, int size) {
        List<Integer> result = new ArrayList<>();
        if (totalFee < 0 && size < 1) {
            return Collections.emptyList();
        }
        // Minimum amount per red packet
        int minFee = 30;
        int amount, sum = 0;
        int remainingNumber = size;
        int i = 1;
        while (remainingNumber > 1) {
            int maxFee = Math.min(2 * (totalFee / remainingNumber), totalFee - ((size - i + 1) * minFee) + minFee);
            amount = RandomUtils.nextInt(minFee, maxFee);
            sum += amount;
            System.out.println("The first" + i + "The red envelope amount received by individuals is:" + amount);
            totalFee -= amount;
            remainingNumber--;
            result.add(amount);
            i++;
        }
        result.add(totalFee);
        System.out.println("The first" + i + "The red envelope amount received by individuals is:" + totalFee);
        sum += totalFee;
        System.out.println("The total amount of red packets issued is:" + sum);
        return result;
    
    }
    Copy the code

Two, get a red envelope

This article addresses

Three, New Year gesture to get red envelopes

This article addresses